QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#28224 | #2271. High-Tech Detective | Suika_predator# | WA | 3ms | 3704kb | C++20 | 2.4kb | 2022-04-12 20:41:57 | 2022-04-29 09:17:38 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 5050;
const int mod = 1e9+7;
inline void add(int &a,const int &b){ a+=b;if(a>=mod)a-=mod; }
int fac[maxn],ifac[maxn];
int pw(int x,int k)
{
int re=1;
for(;k;k>>=1,x=1ll*x*x%mod) if(k&1)
re=1ll*re*x%mod;
return re;
}
int inv(int x){ return pw(x,mod-2); }
void pre()
{
fac[0]=1; for(int i=1;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
ifac[maxn-1]= inv(fac[maxn-1]);
for(int i=maxn-2;i>=0;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
int C(int i,int j)
{
if(i<j) return 0;
return 1ll*fac[i]*ifac[j]%mod*ifac[i-j]%mod;
}
int invC(int i,int j)
{
if(i<j) return 0;
return 1ll*ifac[i]*fac[j]%mod*fac[i-j]%mod;
}
int n;
int o[maxn],xi[maxn];
int now[maxn],num0,num1,num2;
int f[2][maxn]; ////////////////
char str[10];
int main()
{
ios_base::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=2*n;i++)
{
cin>>str; o[i]= str[0]=='I'?1:0;
cin>>xi[i];
if(xi[i])
{
now[xi[i]] |= 1<<o[i];
}
}
for(int i=1;i<=n;i++)
{
if(now[i]==0) num0++;
if(now[i]==1) num1++;
if(now[i]==2) num2++;
}
int ni=0;
f[ni][0]=1;
int hole0=0,hole1=0;
int sum1=0,sum0=0;
for(int i=1;i<=2*n;i++)
{
ni=!ni;
for(int j=0;j<=i-1;j++)
{
int &temp = f[!ni][j];
if( xi[i] && now[xi[i]]==3 )
{
//f[i][j]=f[i-1][j];
add(f[ni][j],temp);
temp=0;
continue;
}
if( o[i]==1 )
{
if(xi[i]==0)
{
add(f[ni][j],1ll*temp*(num1-sum0-(hole1-j))%mod);
add(f[ni][j+1],1ll*temp*(num0-j)%mod);
// f[i-1][j]*(num1-sum0-(hole1-j)) -> f[i][j]
// f[i-1][j]*(num0-j) -> f[i][j+1]
}
else
{
add(f[ni][j],temp);
//f[i][j]=f[i-1][j];
}
}
else
{
if(xi[i]==0)
{
// f[i-1][j]*(j+sum1-hole0) -> f[i][j]
add(f[ni][j], 1ll*temp*(j+sum1-hole0)%mod);
}
else
{
int k=hole1-j-sum0;
int ku=num1-sum0;
add(f[ni][j], 1ll*temp* ( 1-1ll*C(ku-1,k)*invC(ku,k)%mod+mod )%mod);
// 1ll* f[i-1][j]*( 1-1ll*C(ku-1,k)*invC(ku,k)%mod+mod )%mod -> f[i][j];
}
}
temp=0;
}
if( xi[i]>0 && now[xi[i]]==1 ) sum0++;
if( xi[i]>0 && now[xi[i]]==2 ) sum1++;
if( xi[i]==0 && o[i]==0 ) hole0++;
if( xi[i]==0 && o[i]==1 ) hole1++;
// cout<<i<<" : ";
// for(int j=0;j<=i;j++) cout<<' '<<f[ni][j];
// cout<<endl;
}
cout<<f[ni][num0]<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 3576kb
input:
4 I 1 I 0 O 0 I 0 O 2 I 4 O 0 O 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
3 I 0 I 0 I 0 O 0 O 0 O 0
output:
36
result:
ok single line: '36'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3704kb
input:
1 I 0 O 1
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 3ms
memory: 3580kb
input:
2 I 0 I 1 O 1 O 0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
4 I 0 I 0 O 0 O 0 I 0 I 3 O 0 O 0
output:
24
result:
ok single line: '24'
Test #6:
score: -100
Wrong Answer
time: 3ms
memory: 3608kb
input:
8 I 0 I 0 I 0 I 8 I 4 I 0 O 1 I 0 O 8 O 4 I 5 O 0 O 0 O 5 O 0 O 7
output:
432
result:
wrong answer 1st lines differ - expected: '576', found: '432'