QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#322222 | #5743. Palindromic Polynomial | EverlastingEternity | WA | 157ms | 4216kb | C++14 | 3.6kb | 2024-02-06 15:36:18 | 2024-02-06 15:36:18 |
Judging History
answer
#pragma GCC optimize("Ofast,fast-math")
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
bool _u;
typedef long long ll;
typedef double db;
typedef pair <int, int> pii;
#define ci const int
template <class T>
inline void chmax(T &x, const T &y) { if(x < y) x = y; }
template <class T>
inline void chmin(T &x, const T &y) { if(x > y) x = y; }
#define mp make_pair
#define fi first
#define se second
#define pc putchar
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define ppc __builtin_popcount
#define ctz __builtin_ctz
#define clr(a) memset(a, 0, sizeof(a))
#define rep(i, l, r) for(int i = l, i##end = r; i <= i##end; ++ i)
#define per(i, r, l) for(int i = r, i##end = l; i >= i##end; -- i)
#define fsub(T, S) for(int T = S, T##_f = T; T; T = (T - 1) & T##_f)
#define fsubm(T, S) for(int T = S, T##_f = T; T; T = (T - 1) & T##_f) if(T & (T##_f & -T##_f))
#define Sin(S, i) ((S) >> (i) & 1)
char inputbuf[1 << 23], *p1 = inputbuf, *p2 = inputbuf;
#define getchar() (p1 == p2 && (p2 = (p1 = inputbuf) + fread(inputbuf, 1, 1 << 23, stdin), p1 == p2) ? EOF : *p1++)
inline int read() {
int res = 0; char ch = getchar(); bool f = true;
for(; ch < '0' || ch > '9'; ch = getchar())
f &= ch != '-';
for(; ch >= '0' && ch <= '9'; ch = getchar())
res = res * 10 + (ch ^ 48);
return f ? res : -res;
}
const int N = 1e4 + 15, P = 1e9 + 9, i2 = (P + 1) / 2;
map <ll, ll> S;
int n, d, lim = 1e4, nf, ng;
ll X[N], Y[N];
ll g[N], f[N], h[N];
bool ill[N];
bool _v;
ll poww(ll x, ll y = P - 2) {
ll res = 1;
for(; y; y >>= 1, x = x * x % P)
if(y & 1) res = res * x % P;
return res;
}
ll mod(ll x) {
return x >= P ? x - P : x;
}
void ins(int x) {
per(i, n, 1) g[i] = mod(g[i - 1] - x * g[i] % P + P);
g[0] = mod(P - x * g[0] % P);
}
void del(int x) {
ll ix = poww(x);
g[0] = (P - g[0]) * ix % P;
rep(i, 1, n) g[i] = (g[i - 1] - g[i] + P) * ix % P;
}
void lgg() {
clr(f); clr(g);
g[0] = 1;
rep(j, 1, n) ins(X[j]);
rep(j, 1, n) {
ll co = 1;
rep(k, 1, n) if(k != j) co = co * (X[j] - X[k] + P) % P;
co = poww(co) * Y[j] % P;
del(X[j]);
rep(k, 0, n) (f[k] += co * g[k]) %= P;
ins(X[j]);
}
}
#define exi { puts("-1"); return ; }
ll calc(ll x) {
ll res = 0;
per(i, d, 0) res = (res * x + h[i]) % P;
return res;
}
void solve() {
n = read();
S.clear();
clr(ill);
ll y0 = -1;
rep(i, 1, n) X[i] = read();
rep(i, 1, n) Y[i] = read();
rep(i, 1, n) {
if(X[i] == 0) {
y0 = Y[i];
if(y0 == 0) exi
continue;
}
if(S.find(X[i]) != S.end()) {
if(S[X[i]] != Y[i]) exi
continue;
}
S[X[i]] = Y[i];
ll ix = poww(X[i]), y = Y[i];
if(S.find(ix) != S.end())
rep(j, 0, lim) {
if(y != S[ix]) ill[j] = 1;
(y *= ix) %= P;
}
}
d = -1;
per(i, lim, 0) if(!ill[i]) { d = i; break; }
if(d == -1) exi
rep(i, 1, n) if(X[i]) S[poww(X[i])] = Y[i] * poww(X[i], P - 1 - d) % P;
n = 0;
for(auto p : S) X[++ n] = p.fi, Y[n] = p.se;
lgg();
nf = ng = n;
while(nf && !f[nf]) -- nf;
while(ng && !g[ng]) -- ng;
if(nf > d) exi
rep(i, 0, d) h[i] = mod(f[i] + f[d - i]) * i2 % P;
rep(i, 1, n) assert(calc(X[i]) == Y[i]);
if(h[0] == 0 || y0 != -1 && h[0] != y0) {
if(ng > d) exi
if(h[0] == 0) y0 = 1;
ll k = (y0 - h[0] + P) * poww(mod(g[0] + g[d])) % P;
rep(i, 0, d) (h[i] += k * (g[i] + g[d - i])) %= P;
}
printf("%d\n", d);
rep(i, 0, d) printf("%lld ", h[i]);
pc(10);
}
signed main() {
//freopen("yinfuxixuer.in", "r", stdin);
//freopen("yinfuxixuer.out", "w", stdout);
int T = read();
while(T --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 4172kb
input:
8 2 0 1 2 4 3 0 1 2 2 10 36 4 0 1 2 3 1 4 9 16 5 0 1 2 3 4 1 25 961 14641 116281 2 2 500000005 5 375000004 2 2 500000005 5 375000004 2 2 500000005 1 2 3 2 500000005 3 5 375000004 10
output:
10000 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok OK (8 test cases)
Test #2:
score: 0
Accepted
time: 99ms
memory: 4100kb
input:
10 100 24820 26839 18512 6097 25046 22372 21548 2359 17721 9732 16436 12710 14995 4112 17855 28268 28129 13501 23470 16561 8633 29875 13119 10835 15842 14515 5588 10553 28603 3849 12379 17065 15155 15079 26029 3003 2878 29555 3609 8886 2841 17696 9648 4533 5924 12557 25988 29061 26075 28447 28620 20...
output:
10000 991763663 84183251 817748541 751820472 274705299 514844809 913324462 820197929 612599255 544464585 308799257 597748867 819625620 166080135 361705698 661132829 605251716 496947604 920996634 950546155 264960302 137225471 323125051 668269766 400370855 394998826 746252932 404806900 592103371 32196...
result:
ok OK (10 test cases)
Test #3:
score: 0
Accepted
time: 157ms
memory: 4216kb
input:
1 1000 112 16069 28329 8759 23521 1674 11755 9574 19846 5769 27729 17604 3648 29441 25349 24311 6088 2549 6437 16310 25464 25775 20988 21334 3451 1098 26971 3856 28015 24136 18147 24690 4690 4517 14412 29017 14675 5027 18071 4428 29328 28568 12161 2780 23653 21472 21227 23968 1331 24977 7243 13552 6...
output:
10000 595082465 500379518 192552113 852814130 247309815 962855771 99418958 331067561 535148608 579727297 259903516 111909078 37735507 500838722 255719385 725870731 519455673 56193620 436557088 32184394 483678212 529399895 706324015 477741359 718334153 959571726 408401068 308036831 271560940 58661475...
result:
ok OK (1 test case)
Test #4:
score: 0
Accepted
time: 4ms
memory: 4036kb
input:
21 8 1000000008 191950673 311042534 341446923 351508511 730849637 837221839 949983050 2 199758730 296525790 620719636 271569769 48989015 768611306 77253955 8 1 6208459 29989762 187741303 265062278 393002943 957915451 986759042 2 603327752 901822821 349826936 933716294 123962049 672761843 702453404 8...
output:
8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 652846242 409604846 504991502 825789907 155114...
result:
ok OK (21 test cases)
Test #5:
score: -100
Wrong Answer
time: 4ms
memory: 3980kb
input:
21 8 1000000008 82536156 95733833 173997609 176779824 454444312 524861364 586834996 4 841461190 384072747 954440743 152490383 894790857 441089967 851188211 8 1 62386922 117616238 344901582 692317472 798339321 934650757 967500526 4 923589217 91616771 328945919 250367604 465360899 562911768 673536418 ...
output:
8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 1 402152700 555518469 915431388 308143286 915431388 555518469 402152700 1 8 2 0 0 0 0 0 0 0 2 8 1 745551825 433482217 754346262 ...
result:
wrong answer Test case 9: Mismatch at point x=0. Expected A(x)=2, got A(x)=1. (test case 9)