QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515190 | #2271. High-Tech Detective | Lavender_Field# | WA | 1ms | 5868kb | C++20 | 1.8kb | 2024-08-11 15:52:07 | 2024-08-11 15:52:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5005;
#define int long long
int ref_[N],ban[N],p[N],zero[N];
int f[N][N],n;
int t[N],cnt1,cnt2;
int a[N],b[N];
const int mod=1e9+7;
signed main(){
scanf("%lld",&n);
for(int i=1;i<=2*n;i++){
char tmp[5];
scanf("%s",tmp);
if(tmp[0]=='I'){
cnt1++;
scanf("%lld",&a[cnt1]);
if(a[cnt1]==0) zero[cnt1]=1;
else t[a[cnt1]]++;
}
else{
cnt2++;
scanf("%lld",&b[cnt2]);
if(b[cnt2]!=0) t[b[cnt2]]++;
ref_[cnt2]=cnt1;
}
}
for(int i=1;i<=n;i++){
if(t[a[i]]==2){
ban[i]=1;
}
}
for(int i=1;i<=n;i++){
zero[i]+=zero[i-1];
ban[i]+=ban[i-1];
}
for(int i=1;i<=n;i++){
p[i]=ref_[i]-(i-1)-ban[ref_[i]];
}
f[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
if(b[i]==0){
if(p[i]-(zero[ref_[i]]-j)>0){
f[i][j]=(f[i][j]+f[i-1][j]*(p[i]-(zero[ref_[i]]-j)))%mod;
}
if(zero[ref_[i]]-(j-1)>0){
f[i][j]=(f[i][j]+f[i-1][j-1]*(zero[ref_[i]]-(j-1)))%mod;
}
}
else if(t[b[i]]==1){
if(zero[ref_[i]]-(j-1)>0){
f[i][j]=(f[i][j]+f[i-1][j-1]*(zero[ref_[i]]-(j-1)))%mod;
}
}
else{
f[i][j]=f[i-1][j];
}
}
}
int ans=f[n][zero[ref_[n]]];
int cnt=0;
for(int i=1;i<=n;i++){
if(!t[i]) cnt++;
}
while(cnt){
ans=ans*cnt%mod;
cnt--;
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
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: 3928kb
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: 0ms
memory: 3976kb
input:
1 I 0 O 1
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
2 I 0 I 1 O 1 O 0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3932kb
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: 0
Accepted
time: 0ms
memory: 3868kb
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:
576
result:
ok single line: '576'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 5868kb
input:
16 I 5 I 4 I 2 I 1 I 10 I 6 I 14 I 3 I 11 I 7 I 16 O 0 O 7 I 15 O 1 I 8 I 12 O 4 O 11 O 0 I 13 O 14 O 12 O 13 I 0 O 5 O 0 O 0 O 0 O 0 O 0 O 3
output:
0
result:
wrong answer 1st lines differ - expected: '2400', found: '0'