QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#931483 | #10111. Dividing Chains | liuhengxi | AC ✓ | 67ms | 3584kb | C++14 | 1.7kb | 2025-03-11 10:43:01 | 2025-03-11 10:43:01 |
Judging History
answer
// created: 2025-03-11 10:22:49
#include<cstdio>
#include<cctype>
#include<algorithm>
#define F(i,l,r) for(int i=(l),i##_end=(r);i<i##_end;++i)
#define I128 //||is_same<T,__int128_t>::value||is_same<T,__uint128_t>::value
using namespace std;
template<typename T>constexpr bool is_integral_128=(bool)is_integral<T>::value I128;
template<typename T>struct read_dec1{enable_if_t<is_integral_128<T>,T> &x;};
constexpr struct read_dec1_conv{template<typename T>read_dec1<T> operator+(T &x)const{return read_dec1<T>{x};}}D;
template<typename T>enable_if_t<is_integral_128<T>,void> readmain(T &x)
{
bool neg=false;int c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')neg=true;
for(x=0;isdigit(c);c=getchar())x=(T)(10*x+(c-'0'));
if(neg)x=-x;
}
template<typename T>void readmain(read_dec1<T> &y){readmain(y.x);--y.x;}
template<typename T>T& read(T &&x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &&x,Tr&&... r){readmain(x);read(r...);}
typedef unsigned long long ull;
constexpr int N=505,MOD=998244353;
void reduce(int &x){if(x>=MOD)x-=MOD;}
void reduce_(int &x){if(x<0)x+=MOD;}
int n,a[N],f[N][N][2];
int main()
{
read(n);
F(i,0,n)--read(a[i]);
F(i,0,n+1)f[i][i][0]=1;
for(int l=n;~--l;)F(r,l+1,n+1)
{
if(a[l]==a[r-1])
{
f[l][r][0]=1;
f[l][r][1]=r-l==1;
continue;
}
F(i,l+1,r)f[l][r][1]=(int)((f[l][r][1]+(ull)f[l][i][1]*f[i][r][0])%MOD);
if(a[l]==a[l+1])reduce_(f[l][r][0]-=f[l+2][r][0]);
if(a[r-1]==a[r-2])reduce_(f[l][r][0]-=f[l][r-2][0]);
reduce(f[l][r][0]+=f[l][r][1]);
reduce(f[l][r][0]+=f[l][r][1]);
reduce_(f[l][r][1]=f[l][r][0]-f[l][r][1]);
}
printf("%d\n",f[0][n][0]);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1536kb
input:
3 2 3 3
output:
3
result:
ok "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1536kb
input:
5 1 1 3 3 5
output:
29
result:
ok "29"
Test #3:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
9 1 2 3 5 5 6 7 8 9
output:
26276
result:
ok "26276"
Test #4:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 1 2 2 3 4 5 8 10 10 10
output:
42088
result:
ok "42088"
Test #5:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 1 2 4 5 5 5 5 6 10 10
output:
17210
result:
ok "17210"
Test #6:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 1 2 3 5 6 6 6 8 9 9
output:
41826
result:
ok "41826"
Test #7:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 2 6 6 7 7 8 9 10 10 10
output:
26684
result:
ok "26684"
Test #8:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 1 1 3 3 4 5 9 9 10 10
output:
33378
result:
ok "33378"
Test #9:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 1 1 2 3 4 4 9 9 10 10
output:
33348
result:
ok "33348"
Test #10:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 1 3 4 4 5 5 8 8 10 10
output:
32826
result:
ok "32826"
Test #11:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 1 3 3 4 5 6 9 9 9 10
output:
42136
result:
ok "42136"
Test #12:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 1 1 1 2 2 4 4 5 5 6
output:
16274
result:
ok "16274"
Test #13:
score: 0
Accepted
time: 0ms
memory: 1664kb
input:
10 1 3 5 5 5 6 7 8 8 9
output:
42088
result:
ok "42088"
Test #14:
score: 0
Accepted
time: 67ms
memory: 3584kb
input:
500 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12...
output:
316934967
result:
ok "316934967"
Test #15:
score: 0
Accepted
time: 67ms
memory: 3456kb
input:
500 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 7 7 7 7 7 8 8 9 9 10 10 10 10 10 11 11 11 11 12 12 12 12 12 13 13 14 14 14 14 15 15 15 16 16 16 17 17 17 17 17 17 17 18 18 18 18 18 18 19 19 19 19 19 19 19 19 20 21 21 21 21 21 21 22 22 22 22 22 22 22 22 22 23 23 23 23 23 23 23 ...
output:
211204090
result:
ok "211204090"
Test #16:
score: 0
Accepted
time: 67ms
memory: 3456kb
input:
500 1 1 1 2 3 4 4 4 4 4 4 4 4 5 5 5 6 7 7 7 7 8 8 9 9 10 10 10 10 10 10 11 11 11 11 11 11 12 12 12 12 12 12 13 13 13 14 14 14 14 15 15 15 16 16 16 16 18 19 19 19 19 19 20 20 21 21 21 22 22 22 22 22 22 23 23 24 24 24 24 24 24 24 25 26 26 27 27 27 28 28 29 29 29 30 30 31 31 31 31 31 32 32 32 32 33 33 ...
output:
66910402
result:
ok "66910402"
Test #17:
score: 0
Accepted
time: 66ms
memory: 3456kb
input:
500 1 1 2 2 2 2 3 4 4 4 4 4 5 6 6 7 8 8 8 9 9 9 9 9 10 10 11 12 12 13 13 14 14 15 15 15 16 16 17 17 17 17 17 17 18 18 18 19 19 19 19 19 20 20 21 21 21 21 22 22 22 23 23 24 24 25 25 25 25 26 26 26 27 27 27 28 28 28 28 29 30 30 31 31 32 32 33 33 34 34 34 35 35 35 36 36 36 36 37 37 37 37 37 37 38 38 39...
output:
778673575
result:
ok "778673575"
Test #18:
score: 0
Accepted
time: 67ms
memory: 3584kb
input:
500 1 1 1 2 4 4 4 5 6 6 6 7 7 8 8 8 8 9 9 13 14 14 14 15 15 16 16 16 16 16 17 18 19 20 21 21 21 22 22 22 22 23 23 24 24 24 25 25 26 26 26 27 27 28 28 28 28 28 28 30 30 30 31 31 32 32 33 34 34 34 35 36 36 36 37 37 39 39 39 40 40 40 41 42 42 42 43 43 43 44 44 45 45 45 46 47 48 48 48 49 49 49 49 50 51 ...
output:
626585352
result:
ok "626585352"
Test #19:
score: 0
Accepted
time: 67ms
memory: 3584kb
input:
500 1 2 3 3 4 5 5 5 6 6 8 8 8 10 11 12 13 13 13 13 13 13 14 14 15 15 17 18 18 18 18 19 19 20 20 20 21 21 21 25 25 26 26 27 27 29 30 30 30 32 33 33 33 34 34 34 35 36 36 37 37 37 38 38 38 39 40 40 40 42 42 43 44 44 45 45 46 47 47 48 50 54 54 55 55 57 57 57 58 59 59 60 61 62 63 63 63 64 65 65 66 66 66 ...
output:
918943801
result:
ok "918943801"
Test #20:
score: 0
Accepted
time: 66ms
memory: 3584kb
input:
500 1 1 2 3 3 3 4 4 5 6 7 9 9 9 11 12 13 13 14 14 14 14 15 15 16 19 19 20 22 23 24 25 25 26 26 27 30 31 32 33 33 33 34 35 35 36 37 38 38 39 43 43 45 45 46 46 47 47 48 48 50 51 51 52 52 52 52 53 54 57 58 58 58 59 60 60 61 62 62 63 63 64 64 64 65 66 66 66 68 68 70 70 70 72 72 73 73 73 75 75 75 76 78 7...
output:
593100090
result:
ok "593100090"
Test #21:
score: 0
Accepted
time: 66ms
memory: 3456kb
input:
500 1 2 2 3 4 4 5 5 6 6 7 8 9 11 11 12 12 13 14 14 14 14 16 17 19 19 20 21 22 22 24 26 26 26 27 27 28 28 29 29 35 39 40 41 42 43 46 47 48 49 49 50 50 51 52 52 52 56 56 56 56 57 59 59 59 60 61 61 65 66 68 69 69 71 71 72 72 73 73 74 74 75 75 76 76 76 79 80 82 82 84 85 87 87 88 88 89 90 91 91 91 94 95 ...
output:
51077903
result:
ok "51077903"
Test #22:
score: 0
Accepted
time: 67ms
memory: 3456kb
input:
500 1 2 3 3 4 4 4 5 6 6 7 9 10 11 11 12 14 14 15 15 15 16 16 17 17 17 18 18 18 18 18 19 19 20 20 21 22 23 24 25 25 25 31 32 32 32 32 33 33 34 35 36 36 37 37 38 38 45 46 47 48 50 50 51 52 52 53 56 58 60 61 61 61 61 62 62 62 62 63 63 63 63 63 64 64 65 67 67 68 71 72 73 74 74 75 75 76 77 77 77 77 77 77...
output:
645029056
result:
ok "645029056"
Test #23:
score: 0
Accepted
time: 67ms
memory: 3584kb
input:
500 1 1 2 2 2 6 8 8 9 9 11 11 11 12 13 13 13 13 15 16 16 19 19 19 20 20 20 20 22 23 24 25 25 26 27 29 31 31 33 33 33 35 35 39 39 39 40 40 40 45 46 46 47 47 47 48 49 50 52 53 53 53 54 55 57 57 58 59 61 62 64 64 66 66 66 68 69 70 71 72 74 74 75 75 76 76 78 80 81 83 83 84 85 85 85 86 88 89 90 90 91 92 ...
output:
799979293
result:
ok "799979293"
Test #24:
score: 0
Accepted
time: 0ms
memory: 1536kb
input:
1 1
output:
1
result:
ok "1"
Test #25:
score: 0
Accepted
time: 65ms
memory: 3584kb
input:
500 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 101 ...
output:
903664836
result:
ok "903664836"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 ...
output:
1
result:
ok "1"
Extra Test:
score: 0
Extra Test Passed