ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215372 | #2162. 无限手套 | naroto2022 | 5 | 4ms | 1132kb | C++ | 1.1kb | 2024-11-28 21:55:28 | 2024-11-28 23:13:13 |
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int mod=998244353;
const int MN=1005;
ll n,m,q,x[MN],a[MN],b[MN],ans;
void write(ll n){if(n<0){putchar('-');write(-n);return;}if(n>9)write(n/10);putchar(n%10+'0');}
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
void work(){
ll res=1;
for(int i=1; i<=n; i++){
ll num=(a[i]*x[i]%mod*x[i]%mod+b[i]*x[i]%mod+1)%mod;
res=res*num%mod;
}
ans=(ans+res)%mod;
}
void dfs(ll step, ll num){
if(num>m) return;
if(step==n){
x[step]=m-num;
work();
return;
}
for(int i=0; i<=m-num; i++){
x[step]=i;
dfs(step+1,num+i);
}
}
int main(){
n=read();
for(int i=1; i<=n; i++) a[i]=read(),b[i]=read();
q=read();
while(q--){
m=read();ans=0;
for(int i=1; i<=n; i++) x[i]=0;
dfs(1,0);
write(ans);putchar('\n');
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 4ms
memory: 1132kb
input:
10 21 59 15 27 62 71 100 98 88 16 62 25 88 66 72 71 29 31 1 0 10 2 2 3 2 4 5 8 5 6 5
output:
448551 448551 114612322 448551 728853470 277267547 83320298 277267547 38592888 277267547
result:
ok 10 lines
Test #2:
score: 0
Time Limit Exceeded
input:
17 73 29 79 15 100 35 34 97 39 50 3 48 45 68 47 50 3 28 73 85 89 87 55 46 14 54 49 88 42 73 44 2 16 ...
output:
result:
Test #3:
score: 0
Time Limit Exceeded
input:
20 27 19 18 92 81 51 63 60 32 34 51 84 33 42 74 60 77 36 6 21 24 17 75 92 31 53 31 80 8 30 79 26 83 ...
output:
result:
Test #4:
score: 0
Time Limit Exceeded
input:
25 26 7 38 93 23 54 7 73 19 76 82 2 56 27 97 81 54 28 54 21 62 43 34 40 60 53 15 36 70 16 69 66 63 8...
output:
result:
Test #5:
score: 0
Time Limit Exceeded
input:
27 80 18 40 71 21 78 53 67 24 18 97 21 56 24 10 32 36 17 48 23 45 44 77 94 93 11 35 32 52 57 73 51 6...
output:
result:
Test #6:
score: 0
Time Limit Exceeded
input:
30 42 32 4 11 64 52 52 45 8 29 27 81 57 52 51 42 52 85 27 61 69 46 18 43 69 87 77 92 5 23 69 15 21 8...
output:
result:
Test #7:
score: 0
Time Limit Exceeded
input:
500 35 33 42 54 68 92 11 31 78 89 89 33 12 43 40 25 89 74 10 96 72 79 41 27 26 9 89 3 24 32 90 22 86...
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
800 67 2 17 90 7 2 80 77 15 8 96 71 77 85 67 83 30 67 21 37 95 0 1 70 69 83 8 28 42 80 32 99 35 13 8...
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
1000 117036880 742743701 56908371 507994295 14078772 65839630 907546488 34355343 620471543 368910184...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
1000 913953750 388577668 962198313 857512157 801529469 683598255 815720687 278538934 837931460 95491...
output:
result:
Test #11:
score: 0
Time Limit Exceeded
input:
1000 686221334 956155197 638206740 299677636 12110365 985957201 296066012 395725665 135750350 202076...
output:
result:
Test #12:
score: 0
Time Limit Exceeded
input:
1000 797564334 746000325 114543902 483936681 721653706 427330786 783028161 561100881 560205639 93358...
output:
result:
Test #13:
score: 0
Time Limit Exceeded
input:
1000 839212319 281284893 986615727 337004261 337283416 832217943 139479834 143482354 718642613 79109...
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
1000 256682454 224905163 546469163 405500779 694909527 452737645 118757654 446812736 305219239 49932...
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
1000 896922349 6803764 761865535 943048070 88880191 606683203 70560593 543433355 840830392 692058868...
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
1000 449301829 90031054 325997406 72341047 30416088 913003710 735565029 221233542 491751571 62166318...
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
1000 832954961 166377984 853572866 869031810 703004519 916522551 674441360 532019428 604496 80785481...
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
1000 630591319 431364812 551848923 931390133 383831685 842422164 638941693 967379955 11797927 362876...
output:
result:
Test #19:
score: 0
Time Limit Exceeded
input:
1000 787106265 727082581 227535146 533287459 837875354 738523208 652170865 583327908 506011496 84943...
output:
result:
Test #20:
score: 0
Time Limit Exceeded
input:
1000 756021044 519638624 79079358 955991362 303396062 299442290 396653454 370013814 118684193 153986...