Cod sursa(job #507696)

Utilizator ciprianfFarcasanu Alexandru Ciprian ciprianf Data 6 decembrie 2010 17:06:13
Problema Oras Scor 55
Compilator cpp Status done
Runda selectie-vianu-2011 Marime 0.86 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 == 4){
		printf("-1\n");
		return 0;
	}
	for(int i = 1; i < n; ++i)
		a[i][i+1] = 1;
	a[n][1] = 1;
	//for(int i = 2; i <= n; i += 2)
		//a[i][mod(i-2)] = 1;
	//if(n % 2){
		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 && dist(j, i) != 1 && a[i][mod(j-1)] == 0) {
						a[i][j] = 1;
						a[j][mod(i-1)] = 1;
					}
	
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j)
			printf("%d", a[i][j]);
		printf("\n");
	}
	return 0;
}