QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#577370 | #4223. 盒 | Starrykiller# | 40 | 187ms | 3904kb | C++23 | 844b | 2024-09-20 10:48:45 | 2024-09-20 10:48:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int p=998244353;
vector<int> a, val;
void solve() {
int n; cin>>n;
a=vector<int>(n); val=vector<int>(n-1);
for (auto &i: a) cin>>i;
for (auto &i: val) cin>>i;
int s=accumulate(begin(a),end(a),0);
vector<int> f(s+1),g(s+1);
int sum=0; g[0]=1;
for (int i=0; i<n-1; ++i) {
sum+=a[i];
for (int j=0,sf=0,sg=0; j<=s; ++j) {
sf=(sf+f[j])%p;
sg=(sg+g[j])%p;
f[j]=(sf+sg*abs(j-sum)%p*val[i])%p;
g[j]=sg;
}
}
int ans=0;
for (int i=0; i<=s; ++i) ans=(ans+f[i])%p;
cout<<ans<<'\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int T; cin>>T;
while (T--) solve();
}
詳細信息
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 1ms
memory: 3792kb
input:
1000 5 1 2 0 0 2 1 1 1 1 5 0 1 0 4 0 1 1 1 1 5 2 3 0 0 0 1 1 1 1 5 1 1 0 3 0 1 1 1 1 5 1 0 2 2 0 1 1 1 1 5 0 3 0 1 1 1 1 1 1 5 2 0 0 3 0 1 1 1 1 5 0 4 0 1 0 1 1 1 1 5 1 2 2 0 0 1 1 1 1 5 1 2 1 0 1 1 1 1 1 5 0 1 1 0 3 1 1 1 1 5 0 0 3 1 1 1 1 1 1 5 4 0 0 1 0 1 1 1 1 5 2 0 1 0 2 1 1 1 1 5 0 1 2 2 0 1 1...
output:
604 684 924 562 550 562 618 684 670 572 738 634 938 624 564 642 1022 684 726 624 586 600 672 526 574 754 822 712 1020 582 658 568 768 592 868 822 754 592 576 564 642 808 564 726 1022 560 560 618 562 606 634 592 938 628 1020 606 690 670 526 618 628 868 670 600 810 684 588 550 648 684 550 562 536 822 ...
result:
ok 1000 lines
Test #2:
score: 5
Accepted
time: 1ms
memory: 3620kb
input:
1000 5 0 0 3 2 0 1 1 1 1 5 0 2 1 0 2 1 1 1 1 5 1 1 0 3 0 1 1 1 1 5 3 1 0 0 1 1 1 1 1 5 1 0 0 1 3 1 1 1 1 5 0 1 3 0 1 1 1 1 1 5 0 5 0 0 0 1 1 1 1 5 1 1 0 3 0 1 1 1 1 5 4 0 1 0 0 1 1 1 1 5 0 1 2 0 2 1 1 1 1 5 1 2 0 1 1 1 1 1 1 5 0 2 1 2 0 1 1 1 1 5 1 1 1 1 1 1 1 1 1 5 3 0 0 0 2 1 1 1 1 5 2 1 0 1 1 1 1...
output:
648 582 562 808 808 574 882 562 1022 606 548 540 512 756 604 672 684 808 810 1260 726 672 568 1260 536 658 684 586 648 582 536 924 586 560 656 726 582 604 754 576 670 592 586 618 564 562 726 628 568 868 600 536 670 714 924 808 548 726 670 574 550 712 550 582 714 562 582 1260 588 882 712 690 1136 684...
result:
ok 1000 lines
Test #3:
score: 5
Accepted
time: 0ms
memory: 3696kb
input:
5 9 2 1 2 1 1 1 0 0 1 64441563 797608723 942502970 533863371 513086090 746473949 428148282 824687114 9 2 1 0 0 1 1 2 1 1 357194979 60738266 185201880 659655681 91157881 186097011 305593400 735854260 9 5 1 0 1 0 1 0 0 1 100945837 161415380 584897137 338229880 478210934 517640875 276897589 404899480 9...
output:
166289283 895455295 733275678 590188223 653043103
result:
ok 5 lines
Test #4:
score: 5
Accepted
time: 0ms
memory: 3588kb
input:
5 9 2 1 0 3 0 1 2 0 0 14399309 615700834 990195320 232910103 497942608 662410204 85583523 29348873 9 0 4 0 0 0 2 3 0 0 666973109 216575957 709836635 363606637 454780119 714712114 868661423 39323875 9 3 3 0 0 0 0 1 1 1 661125856 61965314 875115448 444871086 310288485 430098658 795362211 948050121 9 2...
output:
663021142 691106730 461190819 111225759 954800036
result:
ok 5 lines
Test #5:
score: 5
Accepted
time: 187ms
memory: 3904kb
input:
10 2000 0 0 3 0 3 0 0 0 4 0 4 0 0 0 7 3 3 0 0 0 0 1 1 0 2 3 1 3 3 2 1 0 0 0 0 1 0 1 1 0 1 0 4 2 0 0 0 0 0 0 0 1 1 4 1 2 0 0 3 1 5 0 0 0 1 7 2 3 2 0 1 0 5 0 5 0 0 0 4 2 2 0 0 0 2 0 3 1 1 0 0 4 1 2 1 4 2 0 0 1 1 5 0 4 0 1 0 2 1 0 2 0 0 0 1 1 1 0 0 0 0 4 1 2 0 0 0 1 0 4 2 0 2 1 0 0 1 0 0 0 0 0 2 1 1 3 ...
output:
677203754 806267485 380218391 160903957 636403648 885411081 488211568 884855269 572061500 854586776
result:
ok 10 lines
Test #6:
score: 5
Accepted
time: 187ms
memory: 3828kb
input:
10 2000 0 1 0 2 0 0 1 0 0 3 1 4 1 1 0 0 2 0 0 0 1 1 6 1 0 0 0 0 0 1 0 0 0 0 0 2 0 0 3 0 0 0 0 0 5 1 0 0 2 1 0 1 2 0 5 0 0 0 0 5 4 4 0 2 3 0 0 3 2 3 0 0 1 2 0 1 9 0 1 0 0 0 3 1 6 1 1 0 2 0 0 0 1 1 4 0 3 3 0 2 1 0 1 0 1 0 0 1 1 0 0 6 0 0 4 0 1 0 4 0 0 0 0 1 0 0 2 4 0 1 0 1 1 7 0 1 0 0 0 3 0 0 2 2 1 1 ...
output:
13138131 568953787 794561691 844899130 15143729 565995880 443870964 625990050 170101909 962072317
result:
ok 10 lines
Test #7:
score: 5
Accepted
time: 187ms
memory: 3824kb
input:
10 2000 0 1 0 0 2 2 0 1 1 0 1 0 0 1 2 1 0 0 1 0 0 1 0 2 0 0 0 0 0 1 0 0 0 1 1 1 2 1 0 0 2 0 2 0 0 7 0 0 0 1 3 1 0 1 2 1 0 1 0 2 1 2 2 0 0 0 0 0 0 2 0 1 2 1 0 1 1 0 2 0 3 0 0 1 1 1 0 2 0 0 0 0 1 0 0 0 0 0 0 2 0 1 0 7 0 4 2 0 0 1 0 0 1 0 0 5 0 0 2 3 2 0 1 2 0 1 0 5 0 0 3 3 2 0 1 1 4 0 2 1 0 1 1 1 0 0 ...
output:
927739833 478537355 781908267 477242825 762969873 218922702 324588900 362688816 269194120 851086706
result:
ok 10 lines
Test #8:
score: 5
Accepted
time: 187ms
memory: 3608kb
input:
10 2000 0 0 1 0 3 0 0 0 0 2 2 2 1 0 0 2 0 0 0 1 2 1 0 1 0 0 1 1 0 0 2 0 3 1 2 0 1 0 2 1 0 0 0 0 0 2 1 0 1 0 2 1 0 1 2 0 0 0 0 3 1 3 0 0 0 1 2 0 2 0 3 1 0 1 1 0 1 0 1 0 0 0 3 0 0 2 2 1 1 2 6 0 0 0 0 0 1 1 1 0 0 1 2 0 1 1 4 1 0 0 0 0 2 0 1 1 1 1 2 2 1 3 2 0 1 1 0 0 0 0 2 2 0 0 0 0 0 1 2 0 1 1 1 0 2 0 ...
output:
195292244 782066652 834893430 951491168 373431347 905607285 640769720 147693846 769903465 856040696
result:
ok 10 lines
Test #9:
score: 0
Time Limit Exceeded
input:
10 2000 5 18 179 19 200 71 72 241 70 268 2 32 43 179 39 436 69 57 77 196 212 93 57 128 66 29 248 16 279 102 286 38 12 122 3 84 51 91 39 4 59 31 129 278 3 258 67 171 18 92 80 97 35 48 87 167 22 0 152 110 195 174 59 102 354 136 11 82 87 56 21 78 172 376 79 284 21 51 66 46 97 251 12 92 13 53 31 25 60 9...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
10 2000 85 186 177 278 2 12 67 247 6 197 142 32 47 61 13 33 184 9 198 71 82 157 61 129 204 35 67 91 261 104 47 47 149 126 15 45 74 278 250 56 217 13 38 120 67 2 20 74 0 8 75 43 120 83 52 112 41 98 22 5 74 184 33 194 109 73 109 59 103 6 39 146 118 26 1 9 0 93 8 246 56 83 2 43 101 68 36 103 384 130 17...
output:
result:
Test #11:
score: 0
Time Limit Exceeded
input:
10 2000 28 10 97 27 85 51 88 20 290 96 147 63 31 171 29 55 325 87 73 70 60 23 1 69 370 389 63 74 206 60 28 74 312 346 26 45 389 137 76 137 377 386 5 246 54 344 11 50 55 418 30 76 205 66 41 112 198 106 29 44 176 6 21 1 20 72 74 2 40 135 47 286 104 63 19 112 4 98 6 56 113 189 57 177 1 70 177 26 153 26...
output:
result:
Test #12:
score: 0
Time Limit Exceeded
input:
10 2000 53 99 243 121 0 61 132 124 135 6 191 8 149 19 114 56 93 55 65 35 75 68 2 397 39 117 66 177 203 134 91 67 44 12 94 23 283 176 103 62 273 307 16 126 173 208 54 69 2 15 33 52 82 84 188 178 73 187 39 22 76 27 29 123 18 33 96 66 78 192 9 47 115 60 44 65 203 25 100 54 309 68 71 42 380 121 6 79 295...
output:
result:
Test #13:
score: 0
Time Limit Exceeded
input:
2 200000 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...
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
2 200000 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...
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
2 200000 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...
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
2 200000 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...
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
2 200000 0 0 0 0 1 2 0 0 2 0 0 1 2 0 1 0 0 2 0 1 3 0 0 5 4 1 0 1 2 0 3 2 0 3 0 1 0 1 3 0 0 2 0 3 3 0 1 0 0 0 0 0 2 0 0 0 2 1 0 0 2 2 1 3 1 0 0 1 0 0 0 0 1 7 0 0 0 3 0 3 2 0 5 0 6 0 1 0 1 2 2 0 3 2 5 2 1 0 0 0 1 1 3 1 0 0 4 0 0 0 0 0 1 0 1 1 0 0 3 3 1 0 0 4 1 1 0 0 1 0 2 0 0 2 0 1 0 0 0 2 0 4 0 0 2 1...
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
2 200000 0 2 1 0 0 0 2 0 0 2 2 1 7 3 0 0 3 0 0 4 1 1 0 5 1 1 2 0 0 2 0 2 0 2 0 1 1 2 0 0 1 0 2 3 2 0 0 0 0 2 0 2 0 1 2 0 1 0 4 0 0 2 0 1 0 1 0 0 0 5 0 1 0 0 1 2 1 2 0 2 1 0 0 1 0 0 0 2 0 1 0 1 0 1 0 3 0 2 1 1 1 1 1 1 0 1 0 0 7 2 3 0 0 1 1 1 2 0 0 1 2 0 0 0 2 2 0 0 3 0 0 1 2 0 0 5 1 0 0 0 0 0 3 2 0 0...
output:
result:
Test #19:
score: 0
Time Limit Exceeded
input:
5 500000 11 7 4 2 1 24 2 6 2 5 0 1 1 0 7 1 0 16 3 1 0 2 2 0 9 3 1 5 0 0 0 7 1 13 11 4 0 0 2 5 2 2 3 1 1 11 3 0 0 4 1 4 3 1 0 12 2 4 2 3 6 6 1 3 10 1 1 1 10 1 2 1 0 13 6 18 1 1 7 3 2 12 3 1 1 2 6 12 0 1 9 14 7 3 0 0 1 2 1 3 2 8 2 2 5 2 7 0 4 6 7 11 2 7 1 1 0 1 1 9 6 6 5 1 3 8 0 2 0 0 6 3 0 0 2 0 1 5 ...
output:
result:
Test #20:
score: 0
Time Limit Exceeded
input:
5 500000 13 6 2 0 3 4 3 1 2 2 14 5 0 5 1 3 2 6 0 5 8 0 15 2 0 2 0 11 2 0 1 0 7 0 11 2 6 3 8 0 3 0 1 2 0 1 3 7 0 9 0 0 2 4 5 0 6 20 4 1 1 3 3 1 2 2 1 0 1 12 9 5 3 0 0 1 4 18 0 8 10 8 7 1 4 23 1 4 1 6 0 6 2 1 4 1 2 0 0 4 19 9 4 4 0 3 1 14 2 6 1 14 0 7 0 1 0 1 2 0 17 0 8 19 1 0 2 3 1 0 6 3 0 2 5 3 0 1 ...