QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#341434 | #618. 多项式乘法 | Jsxts_# | 0 | 364ms | 58888kb | C++14 | 1.6kb | 2024-02-29 18:55:18 | 2024-02-29 18:55:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 998244353;
const int G = 1919810;
int ro[2700000],n,m,a[2700000],b[2700000];
ull po[2700000],invG;
ll qpow(ll a,ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res;
}
void init() {
for (int i = 0;i < n;i ++ )
ro[i] = (ro[i>>1] >> 1) | ((i & 1) ? n >> 1 : 0);
}
ull g[2700000];
void NTT(int *f,bool fl) {
for (int i = 0;i < n;i ++ )
g[i] = f[ro[i]];
for (int w = 1;w < n;w <<= 1) {
ull prt = qpow(fl ? G : invG,(mod-1)/(w*2));
po[0] = 1;
for (int i = 1;i <= w;i ++ ) po[i] = po[i-1] * prt % mod;
for (int k = 0;k < n;k += w*2) {
for (int l = 0;l < w;l ++ ) {
int tt = po[l] * g[w|k|l] % mod;
g[w|k|l] = g[k|l]-tt+mod;
g[k|l] += tt;
}
}
if (w == 1<<17)
for (int i = 0;i < n;i ++ ) g[i] %= mod;
}
if (!fl) {
ull inv = qpow(n,mod-2);
for (int i = 0;i < n;i ++ ) f[i] = g[i] % mod * inv % mod;
}
else for (int i = 0;i < n;i ++ ) f[i] = g[i] % mod;
}
int read() {
int s = 0,f = 1;char ch = getchar();
while (!isdigit(ch)) f = ch == '-' ? -1 : 1, ch = getchar();
while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
return s*f;
}
int main() {
n = read()+1,m = read()+1;
invG = qpow(G,mod-2);
int t = n;
for (int i = 0;i < n;i ++ ) a[i] = read();
for (int i = 0;i < m;i ++ ) b[i] = read();
for (n = 1;n <= t+m;n <<= 1);
init();
NTT(a,1),NTT(b,1);
for (int i = 0;i < n;i ++ ) a[i] = 1ll * a[i] * b[i] % mod;
NTT(a,0);
for (int i = 0;i < t+m-1;i ++ ) printf("%d ",a[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 11996kb
input:
96 96 600395131 184265451 942971382 534262851 830366882 542271170 294355449 501371170 797809599 964826049 276651245 375755165 662619442 941920605 328216963 507795473 460271147 874920847 818231910 156789488 590591583 732194508 793983630 93566697 836155866 305319153 432040686 621119061 835023373 57138...
output:
20187436 54553725 873410101 25119037 607522627 219190441 975647780 230781796 337073078 108894342 60626392 585397080 896244276 398866662 900057472 964999352 83985792 785879588 590246472 824559410 47696927 650244660 842314624 957210725 438979001 858370231 532998057 722943995 550632772 53421737 6475791...
result:
wrong answer 1st numbers differ - expected: '683858396', found: '20187436'
Test #2:
score: 0
Wrong Answer
time: 3ms
memory: 12048kb
input:
4992 4994 471194390 313639917 705341086 119536186 430124603 244978845 185588341 13731324 707132801 88167972 927324568 846658454 523684029 5133605 767200778 502476309 539772401 778154025 266136872 183516351 260704325 49303370 475056182 928574546 740424153 277920667 708439854 746983628 839491869 53579...
output:
380523926 964240618 977280774 687055910 697386804 275404969 87017168 152436245 10740488 605367694 731921479 178428572 934770026 118799478 966254039 740665637 249228065 952282354 278941082 968204479 342960769 257302286 213901082 356968477 981167408 735657238 904625927 255358385 327347614 781324591 53...
result:
wrong answer 1st numbers differ - expected: '700935456', found: '380523926'
Test #3:
score: 0
Wrong Answer
time: 10ms
memory: 12508kb
input:
29995 29992 417238081 53580806 733071257 224121793 786137422 127072245 129083351 988357079 246853229 150935424 596994106 975796660 838029970 619117898 328485797 948485083 574261409 79312345 596346086 489787404 929520168 515647000 211731260 50868568 811515357 428215135 498099163 644485329 802849075 3...
output:
405396557 711186431 697470501 772028709 977359671 748651256 966631138 476179968 270546046 294105493 508027791 331261159 802694370 322867163 924947391 200430997 527711331 408738624 443448962 612593553 365747166 628460591 381658010 566406041 643071032 788793976 626498670 936713375 591958896 15777770 7...
result:
wrong answer 1st numbers differ - expected: '115270920', found: '405396557'
Test #4:
score: 0
Wrong Answer
time: 35ms
memory: 16624kb
input:
100000 99993 812398607 947396010 797321381 883949986 56052416 586258761 193247973 611124334 773505112 142179482 565466227 140875825 79890768 893500101 553768089 648879319 480419657 915530184 799329430 494818755 793895824 851865180 459534006 259473419 610037701 472768430 868914058 887444584 588850309...
output:
362216670 124826781 340478339 290031032 3830263 567800602 424349854 383114831 153400130 705952214 476524853 452670997 617181485 653434008 720220592 481562914 149975578 30739104 333083593 691516164 852646384 601360556 363824865 857184440 741917081 198693810 955028389 184102194 390833880 324897780 305...
result:
wrong answer 1st numbers differ - expected: '821875273', found: '362216670'
Test #5:
score: 0
Wrong Answer
time: 364ms
memory: 58888kb
input:
999993 999994 388529697 811245378 165909114 295553883 667981275 78502012 400874009 139394758 249494489 4636487 997712665 259780805 431039016 716944209 709300152 356513646 823185021 699568300 650937921 859190797 899514799 785648601 933470757 627225124 349752104 471458923 456404256 48134357 315599086 ...
output:
453186812 532812460 80002295 405293159 469197803 467579832 146231438 712301475 836262376 611836711 28885782 162381022 468968288 771127445 840361829 473058785 65782930 653179330 91224017 399611902 899100621 188396752 175961137 264789283 206687 632845631 673477989 429754987 389823932 391824211 3212596...
result:
wrong answer 1st numbers differ - expected: '199012842', found: '453186812'