Submission #22443

#TimeUsernameProblemLanguageResultExecution timeMemory
22443카시코이 (#40)Polynomial Quine (KRIII5_PQ)C++11
2 / 7
239 ms1640 KiB
#include <cstdio> int p[210][210]; int inv[210]; int a[210][210], b[210][210]; int x[210], y[210]; bool DEBUG = false; int main(){ int N; scanf("%d", &N); // for 2 point: N = prime inv[1] = 1; for(int i = 2; i < N; i++){ inv[i] = N - N / i * inv[N % i] % N; } for(int i = 0; i < N; i++){ int w = 1, v = N - 1 - i; for(int j = N - 1; j >= 0; j--){ p[i][j] = w; w *= v; w %= N; } } for(int i = 0; i < N; i++){ if(p[i][i] == 0) p[i][i] = N - 1; else p[i][i]--; } if(DEBUG){ puts("array: "); for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++) printf("%d ", p[i][j]); printf("\n"); } printf("\n"); } // get inverse array for(int i = 0; i < N - 1; i++){ for(int j = 0; j < N - 1; j++){ a[i][j] = p[i][j + 1]; } } int n = N - 1; if(DEBUG){ puts("partial array:"); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++) printf("%d ", a[i][j]); printf("\n"); } printf("\n"); } for(int i = 0; i < n; i++) b[i][i] = 1; for(int i = 0; i < n; i++){ if(a[i][i] == 0){ int ni = -1; for(int j = i + 1; j < n; j++){ if(a[j][i] != 0){ ni = j; break; } } for(int j = 0; j < n; j++){ a[i][j] += a[ni][j]; a[i][j] %= N; b[i][j] += b[ni][j]; b[i][j] %= N; } } // printf("diag : %d\n", a[i][i]); int ef = inv[a[i][i]]; for(int j = 0; j < n; j++){ a[i][j] *= ef; a[i][j] %= N; } for(int j = 0; j < n; j++){ b[i][j] *= ef; b[i][j] %= N; } for(int j = 0; j < n; j++){ if(j != i){ int m = a[j][i]; for(int k = 0; k < n; k++){ a[j][k] -= a[i][k] * m % N; if(a[j][k] < 0) a[j][k] += N; } for(int k = 0; k < n; k++){ b[j][k] -= b[i][k] * m % N; if(b[j][k] < 0) b[j][k] += N; } } } } if(DEBUG){ puts("inverse array:"); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++) printf("%d ", b[i][j]); printf("\n"); } printf("\n"); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ a[i][j] = p[i][j + 1]; } } puts("multiple:"); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ int s = 0; for(int k = 0; k < n; k++){ s += a[i][k] * b[k][j]; s %= N; } printf("%d ", s); } printf("\n"); } printf("\n"); } // assume ans[0] for(int v = 0; v < N; v++){ for(int i = 0; i < n; i++){ x[i] = -p[i][0] * v; x[i] %= N; if(x[i] < 0) x[i] += N; } for(int i = 0; i < n; i++) y[i] = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ y[i] += b[i][j] * x[j] % N; if(y[i] >= N) y[i] -= N; } } printf("%d", v); for(int i = 0; i < n; i++) printf(" %d", y[i]); printf("\n"); } return 0; }

Compilation message (stderr)

PQ.cpp: In function 'int main()':
PQ.cpp:12:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int N; scanf("%d", &N);
                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...