QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104365 | #6333. Festivals in JOI Kingdom 2 | oscaryang | 51 | 749ms | 49608kb | C++20 | 1.4kb | 2023-05-10 14:46:07 | 2023-05-10 14:46:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=3005;
int n,P,c[N][N];
int o,w,f[2][N][N][3],ans,all;
inline void inc(int &x,int y) { x+=y-P; x+=(x>>31)&P; }
inline void dec(int &x,int y) { x-=y; x+=(x>>31)&P; }
inline int pls(int x,int y) { x+=y-P; x+=(x>>31)&P; return x; }
int main() {
cin>>n>>P;
for(int i=0;i<N;i++) {
c[i][0]=1;
for(int j=1;j<=i;j++) inc(c[i][j]=c[i-1][j],c[i-1][j-1]);
}
all=1; for(int i=1;i<=(2*n);i+=2) all=1ll*all*i%P;
//cout<<all<<endl;
int *F;
o=0; w=1; f[o][0][0][0]=1;
for(int i=0,val;i<2*n;i++,swap(o,w))
for(int j=0;j<=i;j++)
for(int k=0;k+j<=i;k++) if((k+j&1) == (i&1)) {
/* debug
cout<<endl;
cout<<i<<" "<<j<<" "<<k<<endl;
cout<<0<<" "<<f[o][j][k][0]<<endl;
cout<<1<<" "<<f[o][j][k][1]<<endl;
cout<<2<<" "<<f[o][j][k][2]<<endl;
*/
// l
F = f[o][j][k];
inc(f[w][j][k+1][1],pls(F[0],F[1]));
inc(f[w][j][k+1][2],F[2]);
// r 1
if(k) inc(f[w][j+k-1][0][0],F[1]);
if(j) inc(f[w][j-1][k][0],F[2]);
// r 2
if(j) {
inc(f[w][j-1][k][0],1ll*j*F[0]%P);
inc(f[w][j-1][k][1],1ll*j*F[1]%P);
inc(f[w][j-1][k][2],1ll*(j-1)*F[2]%P);
}
// r 3
if(k) inc(f[w][j+k-1][0][2],1ll*(k-1)*F[1]%P);
//clear
f[o][j][k][0]=f[o][j][k][1]=f[o][j][k][2]=0;
}
dec(ans=all,f[o][0][0][0]);
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 4ms
memory: 40308kb
input:
1 194903119
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 40236kb
input:
2 933234047
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 3ms
memory: 40304kb
input:
3 277793111
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 39772kb
input:
4 355321177
output:
28
result:
ok 1 number(s): "28"
Test #5:
score: 0
Accepted
time: 6ms
memory: 40440kb
input:
5 306636893
output:
358
result:
ok 1 number(s): "358"
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 5
Accepted
time: 2ms
memory: 39352kb
input:
8 361605653
output:
1236922
result:
ok 1 number(s): "1236922"
Test #7:
score: 0
Accepted
time: 1ms
memory: 40180kb
input:
8 995512643
output:
1236922
result:
ok 1 number(s): "1236922"
Test #8:
score: 0
Accepted
time: 1ms
memory: 40444kb
input:
8 101102801
output:
1236922
result:
ok 1 number(s): "1236922"
Test #9:
score: 0
Accepted
time: 2ms
memory: 40004kb
input:
6 458322727
output:
4894
result:
ok 1 number(s): "4894"
Test #10:
score: 0
Accepted
time: 4ms
memory: 39420kb
input:
7 721691819
output:
73884
result:
ok 1 number(s): "73884"
Test #11:
score: 0
Accepted
time: 1ms
memory: 40412kb
input:
7 370629137
output:
73884
result:
ok 1 number(s): "73884"
Subtask #3:
score: 27
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #12:
score: 27
Accepted
time: 4ms
memory: 39396kb
input:
30 779092367
output:
686412377
result:
ok 1 number(s): "686412377"
Test #13:
score: 0
Accepted
time: 4ms
memory: 40708kb
input:
29 963995171
output:
128570082
result:
ok 1 number(s): "128570082"
Test #14:
score: 0
Accepted
time: 0ms
memory: 40044kb
input:
18 666092701
output:
185922458
result:
ok 1 number(s): "185922458"
Test #15:
score: 0
Accepted
time: 1ms
memory: 40136kb
input:
14 671243719
output:
623913899
result:
ok 1 number(s): "623913899"
Subtask #4:
score: 14
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 14
Accepted
time: 749ms
memory: 49504kb
input:
300 463478027
output:
89265245
result:
ok 1 number(s): "89265245"
Test #17:
score: 0
Accepted
time: 727ms
memory: 48112kb
input:
296 567610679
output:
406342763
result:
ok 1 number(s): "406342763"
Test #18:
score: 0
Accepted
time: 738ms
memory: 49608kb
input:
297 609090359
output:
128986577
result:
ok 1 number(s): "128986577"
Test #19:
score: 0
Accepted
time: 4ms
memory: 40660kb
input:
48 759569383
output:
635573072
result:
ok 1 number(s): "635573072"
Test #20:
score: 0
Accepted
time: 28ms
memory: 42320kb
input:
99 298873033
output:
285340078
result:
ok 1 number(s): "285340078"
Subtask #5:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 0
Time Limit Exceeded
input:
3000 752129633
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
0%