QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232394 | #7650. 没有创意的题目名称 | AFewSuns | 100 ✓ | 75ms | 35140kb | C++14 | 2.6kb | 2023-10-30 12:36:03 | 2023-10-30 12:36:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
#define mod 998244353
ll n,lim[2020],nxt[2020][2020],a[2020],invv[2020],ans=0;
il ll solve2(ll x,ll len){
fr(i,0,len-1) if(nxt[i][len]<(x+i)%len) return 0;
if((len-1)>=(n+1)/2){
ll maxx=0;
fr(i,0,n){
maxx=max(maxx,(x+i)%len);
if((maxx+(x+n-i)%len)>n) return 0;
}
return 1;
}
ll mul=1;
fr(i,0,len-1){
if(nxt[i][len]<(x+i)%len) return 0;
ll tmp=(min(n/2,nxt[i][len])-(x+i)%len)/len+1;
mul=mul*tmp%mod;
}
return mul;
}
int main(){
n=read();
fr(i,0,n) lim[i]=read();
invv[1]=1;
fr(i,2,n) invv[i]=(mod-mod/i)*invv[mod%i]%mod;
fr(j,1,n+1){
pfr(i,n,0){
if((i+j)>n) nxt[i][j]=lim[i];
else nxt[i][j]=min(lim[i],nxt[i+j][j]);
}
}
fr(len,1,n){
fr(i,0,n){
a[i]=(min(n/2,nxt[i][len])-i)/len+1;
if(a[i]<=0) a[i]=1;
}
ll mul=1,sum=0;
fr(i,0,len-1) sum+=(nxt[i][len]>=i);
fr(i,0,len-1) mul=mul*a[i]%mod;
fr(k,1,n-len+1){
if(lim[k-1]<(k-1)) break;
sum-=(nxt[k-1][len]>=(k-1));
sum+=(nxt[k+len-1][len]>=(k+len-1));
mul=mul*invv[a[k-1]]%mod*a[k+len-1]%mod;
if(sum==len){
if((k+len-1)>=(n+1)/2) ans=(ans+1)%mod;
else ans=(ans+mul)%mod;
}
}
}
bl ck=1;
fr(i,0,n) if(lim[i]<i) ck=0;
if(ck) ans=(ans-n+1+mod)%mod;
fr(len,1,n){
ans=(ans+solve2(0,len))%mod;
if(len%2==0&&len/2<=lim[0]) ans=(ans+solve2(len/2,len))%mod;
}
write(ans);
}
/*
5
0 5 5 5 5 5
ans:
17
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 0ms
memory: 3416kb
input:
1 0 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 5
Accepted
time: 0ms
memory: 3556kb
input:
5 3 2 4 4 4 5
output:
22
result:
ok 1 number(s): "22"
Test #3:
score: 5
Accepted
time: 0ms
memory: 3408kb
input:
15 6 14 11 1 8 12 5 7 2 15 14 13 9 4 3 12
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 5
Accepted
time: 1ms
memory: 3660kb
input:
30 14 19 7 10 28 12 28 14 14 14 16 13 20 17 20 27 29 24 20 25 26 27 26 24 29 30 28 29 28 29 30
output:
2456
result:
ok 1 number(s): "2456"
Test #5:
score: 5
Accepted
time: 1ms
memory: 3604kb
input:
50 25 49 23 39 9 14 41 15 46 25 23 17 44 39 32 43 19 40 36 50 26 49 50 37 35 29 37 50 44 39 49 32 35 50 42 48 38 42 46 39 41 48 48 43 45 49 46 47 48 49 50
output:
29789
result:
ok 1 number(s): "29789"
Test #6:
score: 5
Accepted
time: 1ms
memory: 5504kb
input:
70 46 43 17 21 23 67 65 19 39 36 28 45 39 25 15 63 46 20 64 69 35 34 66 58 46 48 65 38 35 59 60 49 46 45 34 43 36 57 38 58 56 48 42 46 64 65 58 66 51 63 65 52 54 57 61 70 57 59 69 61 70 64 65 64 67 67 67 68 70 69 70
output:
809261
result:
ok 1 number(s): "809261"
Test #7:
score: 5
Accepted
time: 1ms
memory: 5744kb
input:
100 35 71 90 53 99 79 41 94 37 76 96 30 99 20 69 22 92 34 41 22 98 98 84 73 90 53 13 60 45 96 99 23 28 54 71 47 73 19 46 88 16 90 61 20 50 49 61 69 59 100 69 92 60 33 68 72 79 69 35 23 42 91 17 91 29 99 40 39 59 72 38 75 25 35 80 95 88 76 93 98 70 86 66 52 45 65 47 74 98 55 81 63 80 50 53 12 21 82 4...
output:
75696
result:
ok 1 number(s): "75696"
Test #8:
score: 5
Accepted
time: 2ms
memory: 7844kb
input:
200 70 152 105 124 139 64 50 37 163 115 176 145 30 64 82 102 97 104 108 108 197 199 150 49 69 110 169 134 52 187 125 129 160 112 195 115 81 187 184 123 172 83 110 164 184 24 199 187 192 162 194 67 23 108 41 40 180 148 58 20 30 92 119 108 99 48 105 37 69 128 89 122 132 84 61 149 107 36 190 157 177 12...
output:
3967099
result:
ok 1 number(s): "3967099"
Test #9:
score: 5
Accepted
time: 1ms
memory: 5584kb
input:
99 0 24 43 48 28 45 67 19 76 54 88 68 66 79 93 80 42 28 15 87 49 99 23 75 54 74 39 30 58 46 79 96 54 89 63 51 54 46 90 82 65 16 20 65 59 58 33 70 31 98 58 92 20 58 63 25 31 38 21 81 16 9 71 49 43 85 89 14 38 28 39 18 44 84 52 63 46 60 21 90 10 84 70 89 80 51 71 93 33 98 77 72 49 46 53 89 39 69 97 76
output:
8119
result:
ok 1 number(s): "8119"
Test #10:
score: 5
Accepted
time: 0ms
memory: 12220kb
input:
499 0 275 426 252 73 173 419 64 391 165 154 153 185 207 350 407 414 492 185 289 79 159 443 214 133 220 303 95 165 494 356 422 423 101 170 304 182 316 363 98 123 115 96 412 235 207 219 81 130 202 439 411 215 67 389 100 92 415 378 483 265 412 114 153 219 362 437 233 482 436 164 272 128 326 206 305 278...
output:
129379893
result:
ok 1 number(s): "129379893"
Test #11:
score: 5
Accepted
time: 68ms
memory: 35020kb
input:
2000 0 980 1223 698 1872 1862 626 1968 86 120 633 346 351 1121 1311 516 1615 1521 607 1936 1957 534 71 1388 1776 463 1422 1013 1369 106 1838 364 1366 917 1596 185 233 969 1085 1276 526 300 56 1851 1370 1252 1401 606 1641 1987 1417 1853 1470 808 1992 997 1734 1948 112 1552 1937 1020 846 1037 711 1582...
output:
581584929
result:
ok 1 number(s): "581584929"
Test #12:
score: 5
Accepted
time: 36ms
memory: 34752kb
input:
1985 0 4 4 4 5 5 4 4 4 4 5 4 5 5 4 5 5 5 5 4 5 4 4 5 5 4 5 5 5 4 5 4 5 4 5 4 5 5 4 5 5 5 5 4 4 5 4 4 4 5 4 4 4 5 4 5 5 4 5 4 4 5 4 4 5 5 4 4 4 4 4 4 4 4 4 5 4 5 5 5 5 5 4 4 5 4 5 4 4 5 4 4 4 4 5 4 4 5 4 5 4 4 5 5 4 4 5 5 4 4 5 5 4 5 5 5 4 5 4 5 5 4 5 5 4 5 5 4 4 5 4 5 5 5 4 5 4 4 5 4 4 5 4 5 5 5 4 4...
output:
28
result:
ok 1 number(s): "28"
Test #13:
score: 5
Accepted
time: 31ms
memory: 34964kb
input:
1998 4 5 5 4 5 5 4 4 4 5 4 5 5 5 5 5 5 4 5 5 4 5 5 5 4 5 4 4 5 5 5 5 4 4 4 4 4 5 5 5 5 4 5 5 4 4 4 4 5 5 4 4 5 5 5 5 5 4 5 5 4 4 4 5 4 5 5 5 5 4 4 5 4 4 4 5 4 5 5 5 4 4 4 5 4 4 4 5 5 4 5 4 4 5 5 4 4 4 5 4 4 4 5 4 4 5 5 4 4 4 5 4 4 4 5 4 5 4 5 4 5 4 4 4 4 4 4 4 5 4 4 4 4 5 5 4 5 5 5 5 4 4 4 5 5 5 4 5...
output:
47
result:
ok 1 number(s): "47"
Test #14:
score: 5
Accepted
time: 30ms
memory: 34956kb
input:
1983 20 19 20 19 20 19 19 19 19 19 19 20 19 19 19 20 20 20 19 19 19 19 19 20 20 19 20 19 20 19 19 20 19 19 20 19 19 19 19 20 20 20 19 19 20 19 19 20 20 19 20 19 20 19 19 20 20 20 19 20 20 19 19 19 20 19 20 20 20 20 19 19 20 20 20 20 20 19 19 20 20 19 19 20 19 19 20 19 19 19 20 20 19 20 19 19 19 20 1...
output:
33107
result:
ok 1 number(s): "33107"
Test #15:
score: 5
Accepted
time: 67ms
memory: 34984kb
input:
1980 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
1961191
result:
ok 1 number(s): "1961191"
Test #16:
score: 5
Accepted
time: 68ms
memory: 34840kb
input:
1986 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
1973092
result:
ok 1 number(s): "1973092"
Test #17:
score: 5
Accepted
time: 68ms
memory: 34856kb
input:
1980 584 838 427 912 999 524 1222 1180 243 428 510 1794 298 1866 434 1326 1541 1886 1512 755 1684 1855 674 959 1181 980 592 471 1493 1111 828 1160 184 291 724 1217 1507 1487 1901 1255 1204 1720 655 1442 1656 1143 1638 1628 1206 1841 914 1740 1727 578 998 427 1017 1256 557 352 950 1860 939 1966 1902 ...
output:
642842919
result:
ok 1 number(s): "642842919"
Test #18:
score: 5
Accepted
time: 71ms
memory: 35140kb
input:
2000 1792 1803 1409 1226 437 346 333 1738 889 285 1010 756 327 819 644 1393 499 192 943 1973 517 1506 1458 1977 42 237 1364 1386 324 77 51 654 882 806 1862 696 101 1890 596 85 792 113 1860 1184 1099 282 401 764 1298 1955 1612 872 543 634 1611 739 1232 529 1675 151 1471 587 1090 1348 900 923 1786 118...
output:
737032525
result:
ok 1 number(s): "737032525"
Test #19:
score: 5
Accepted
time: 42ms
memory: 34956kb
input:
1993 1499 1262 1621 607 481 1894 1864 476 586 1262 1630 429 1889 231 1865 328 901 488 954 728 1175 1252 754 1800 1451 1835 1957 1131 1749 1152 1284 1984 573 1310 1277 1725 835 1848 1427 716 1556 1340 1666 773 582 860 1823 431 1967 1899 1850 1003 1873 237 1993 612 1255 1579 733 1155 1026 1000 1404 53...
output:
2976349
result:
ok 1 number(s): "2976349"
Test #20:
score: 5
Accepted
time: 75ms
memory: 34924kb
input:
1998 1219 248 689 1448 677 535 740 1946 45 963 1248 774 754 101 1958 1817 886 1740 1604 1747 1352 1877 213 140 477 627 1068 1028 515 628 1847 1006 1829 739 1178 1218 771 103 732 1698 1542 1521 125 119 529 908 1757 815 110 1398 1486 174 1754 247 1425 1923 1777 1308 1667 75 465 189 1824 1462 597 677 1...
output:
571002932
result:
ok 1 number(s): "571002932"