QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#515221#2271. High-Tech DetectiveLavender_Field#WA 1ms5972kbC++201.8kb2024-08-11 16:09:382024-08-11 16:09:38

Judging History

你现在查看的是最新测评结果

  • [2024-08-11 16:09:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5972kb
  • [2024-08-11 16:09:38]
  • 提交

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;
    int banB=0;
    for(int i=1;i<=n;i++){
        p[i]+=banB;
        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(j!=0 && 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(j!=0 && 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];
                banB++;
            }
        }
    }
    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;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3948kb

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: 3936kb

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: 3916kb

input:

1
I 0
O 1

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3920kb

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: 5972kb

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: 4008kb

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: 0ms
memory: 3984kb

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:

181836400

result:

wrong answer 1st lines differ - expected: '2400', found: '181836400'