Cod sursa(job #227643)

Utilizator wefgefAndrei Grigorean wefgef Data 5 decembrie 2008 00:15:42
Problema Tablete Scor Ascuns
Compilator cpp Status done
Runda Marime 0.8 kb
// Solutia pica pe cazurile in care K = 3 si N este impar

#include <cstdio>
#include <cassert>

const int MAX_N = 1024;

int n, k;
int a[MAX_N][MAX_N];
int cnt;

void fill(int c1, int c2) {
	for (int i = 1; i <= n; ++i)
		for (int j = c1; j <= c2; ++j)
			a[i][j] = ++cnt;
}

int main() {
	assert(freopen("tablete.in", "r", stdin) != NULL);
	assert(freopen("tablete.out", "w", stdout) != NULL);

	assert(scanf("%d %d", &n, &k) == 2);
	assert(3 <= n && n <= 1000);
	assert(1 < k && k < n);

	if (k % 2) {
		if (n % 2) {
			fill(1, 2);
			fill(3, k);
			fill(k + 1, n);
		}
		else {
			fill(1, 1);
			fill(2, k);
			fill(k + 1, n);
		}
	} 
	else {
		fill(1, k);
		fill(k + 1, n);
	}

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			printf("%d ", a[i][j]);
}