/* CEOI 2003 internal solution variant for task "register" */ #include #include #include #define INPUT "register.in" #define OUTPUT "register.out" #define MAX_N 10000 #define FIELDSIZE(bits) (((bits) + CHAR_BIT - 1) / CHAR_BIT) #define FLIPBIT(chars,bit) ((chars)[(bit)/CHAR_BIT] ^= 1<<((bit)%CHAR_BIT)) #define GETBIT(chars,bit) ((chars)[(bit)/CHAR_BIT] >> ((bit)%CHAR_BIT) & 1) void dump(unsigned char m[MAX_N][FIELDSIZE(MAX_N + 1)], int n) { int i, j; for (i=0; i= j */ if (k == n) continue; /* none found -> ignore this column */ if (j != k) /* row k has the "1", move it to row */ { /* j by swapping rows k and j */ memcpy(&tmp, &m[j], fn); memcpy(&m[j], &m[k], fn); memcpy(&m[k], &tmp, fn); } for (k=0; k OK */ if (j == n) ok = 0; /* "0 0 .. 0 = 1" -> not OK */ } out = fopen(OUTPUT, "w"); /* open output (no error handling) */ if (ok) { for (i=n-1; i>=0; i--) /* for all variables (== columns) */ fprintf(out, i ? "%d " : "%d\n", /* print S_i according to equation */ s[i]>=0 ? GETBIT(m[s[i]], n) : 0); /* (== row) s[i] */ } else fprintf(out, "-1\n"); fclose(out); } return 0; }