Cod sursa(job #507607)

Utilizator ciprianfFarcasanu Alexandru Ciprian ciprianf Data 6 decembrie 2010 15:17:50
Problema Oras Scor 55
Compilator cpp Status done
Runda selectie-vianu-2011 Marime 0.75 kb
#include <stdio.h>
#define NMAX 215
int a[NMAX][NMAX];
int n;
inline int mod(int x){
	if(x <= 0) return x += n;
	if(x > n) return x-=n;
	return x;
}
inline int dist(int x, int y){
	if(y-x > 0) return y-x;
	return y-x + n;
}
int main(){
	freopen("oras.in", "r", stdin);
	freopen("oras.out", "w", stdout);
	scanf("%d", &n);
	if(n %2 == 0){
		printf("-1\n");
		return 0;
	}
	for(int i = 1; i < n; ++i)
		a[i][i+1] = 1;
	a[n][1] = 1;
	for(int i = 1; i <= n; ++i)
		a[i][mod(i-2)] = 1;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(i != j) 
				if(dist(i, j) >= 3 && dist(i, j) % 2 == 1) a[i][j] = 1;
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j)
			printf("%d", a[i][j]);
		printf("\n");
	}
	return 0;
}