/* CEOI 2003 internal solution variant for task "register" */ #include #include #define INPUT "register.in" #define OUTPUT "register.out" #define MAX_N 750 typedef char m_element; typedef m_element m_row[MAX_N + 1]; typedef m_row matrix[MAX_N]; int main(void) { int n; /* N */ static matrix m; /* equation matrix */ static int s[MAX_N]; { /* INPUT */ FILE *in; int a[2*MAX_N], i, j; in = fopen(INPUT, "r"); /* open input (no error handling) */ fscanf(in, "%d", &n); /* read N */ for (i=0; i<2*n; i++) fscanf(in, "%d", &a[i]); /* read 2*N numbers into a[] */ fclose(in); 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], sizeof(m_element)*(n+1)); memcpy(&m[j], &m[k], sizeof(m_element)*(n+1)); memcpy(&m[k], &tmp, sizeof(m_element)*(n+1)); } 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 ? m[s[i]][n] : 0); /* (== row) s[i] */ } else fprintf(out, "-1\n"); fclose(out); } return 0; }