QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#414344 | #6333. Festivals in JOI Kingdom 2 | Rafi22# | 51 | 3ms | 10408kb | C++14 | 1.7kb | 2024-05-18 21:40:01 | 2024-05-18 21:40:02 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
ll infl=1000000000000000007;
int mod=998244353;
const int N=3007;
int fac[2*N];
int inv[2*N];
int pot(int x,int p) {int res=1;for(;p;p>>=1) {if(p&1) res=res*x%mod; x=x*x%mod;} return res;}
int npok(int n,int k)
{
if(min(k,n)<0||k>n) return 0;
return fac[n]*inv[n-k]%mod;
}
int DP[2*N][N][3];
void add(int i,int j,int c,int x)
{
DP[i][j][c]+=x;
if(DP[i][j][c]>=mod) DP[i][j][c]-=mod;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n>>mod;
fac[0]=1;
for(int i=1;i<=2*n;i++) fac[i]=fac[i-1]*i%mod;
inv[2*n]=pot(fac[2*n],mod-2);
for(int i=2*n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
int tot=fac[2*n]*inv[n]%mod;
for(int i=1;i<=n;i++) tot=tot*pot(2,mod-2)%mod;
DP[0][0][2]=1;
for(int i=0;i<=2*n;i++)
{
for(int j=0;j<=min(n,i);j++)
{
/*if(DP[i][j][0]>0) cout<<i<<" "<<j<<" "<<0<<" "<<DP[i][j][0]<<endl;
if(DP[i][j][1]>0) cout<<i<<" "<<j<<" "<<1<<" "<<DP[i][j][1]<<endl;
if(DP[i][j][2]>0) cout<<i<<" "<<j<<" "<<2<<" "<<DP[i][j][2]<<endl;*/
if(j>0) add(i+j,0,2,DP[i][j][0]*npok(2*n-i-1,j-1)%mod);
if(j>1) add(i+j-1,1,1,DP[i][j][0]*npok(2*n-i-1,j-2)%mod*(j-1)%mod);
add(i+1,j+1,0,DP[i][j][0]);
add(i+1,j-1,2,DP[i][j][1]);
add(i+1,j+1,1,DP[i][j][1]);
add(i+1,j+1,0,DP[i][j][2]);
}
}
cout<<(tot-DP[2*n][0][2]+mod)%mod;
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 1ms
memory: 3720kb
input:
1 194903119
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3732kb
input:
2 933234047
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
3 277793111
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
4 355321177
output:
28
result:
ok 1 number(s): "28"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3708kb
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: 1ms
memory: 3812kb
input:
8 361605653
output:
1236922
result:
ok 1 number(s): "1236922"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5724kb
input:
8 995512643
output:
1236922
result:
ok 1 number(s): "1236922"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
8 101102801
output:
1236922
result:
ok 1 number(s): "1236922"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
6 458322727
output:
4894
result:
ok 1 number(s): "4894"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
7 721691819
output:
73884
result:
ok 1 number(s): "73884"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3704kb
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: 0ms
memory: 3984kb
input:
30 779092367
output:
686412377
result:
ok 1 number(s): "686412377"
Test #13:
score: 0
Accepted
time: 0ms
memory: 4092kb
input:
29 963995171
output:
128570082
result:
ok 1 number(s): "128570082"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3760kb
input:
18 666092701
output:
185922458
result:
ok 1 number(s): "185922458"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3816kb
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: 3ms
memory: 10408kb
input:
300 463478027
output:
89265245
result:
ok 1 number(s): "89265245"
Test #17:
score: 0
Accepted
time: 0ms
memory: 10404kb
input:
296 567610679
output:
406342763
result:
ok 1 number(s): "406342763"
Test #18:
score: 0
Accepted
time: 0ms
memory: 10356kb
input:
297 609090359
output:
128986577
result:
ok 1 number(s): "128986577"
Test #19:
score: 0
Accepted
time: 1ms
memory: 4220kb
input:
48 759569383
output:
635573072
result:
ok 1 number(s): "635573072"
Test #20:
score: 0
Accepted
time: 0ms
memory: 5260kb
input:
99 298873033
output:
285340078
result:
ok 1 number(s): "285340078"
Subtask #5:
score: 0
Runtime Error
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 0
Runtime Error
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%