QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515209#2271. High-Tech Detectiveurayaha_yahaura#WA 1ms3944kbC++142.5kb2024-08-11 16:02:432024-08-11 16:02:44

Judging History

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

  • [2024-08-11 16:02:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3944kb
  • [2024-08-11 16:02:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+7;
const int mod=1e9+7;
int read(){
    int x=0;
    char c;
    while(!isdigit(c=getchar()));
    while(isdigit(c)){
        x=x*10+(c^48);
        c=getchar();
    }
    return x;
}
struct mint{
    int x;
    mint(int x=0):x(x%mod){}
    friend mint operator +(mint a,mint b){
        a.x+=b.x;
        if(a.x>=mod)
            a.x-=mod;
        return a;
    }
    friend mint operator *(mint a,mint b){
        return mint(1ll*a.x*b.x%mod);
    }
};
int qpow(int a,int x){
    mint A=a,res=1;
    while(x){
        if(x&1)
            res=res*A;
        A=A*A;
        x>>=1;
    }
    return res.x;
}
int n,m,x,cnt,I[N],O[N];
char op[N],a[N];
int pre[N],sufI[N],sufO[N],isufO[N];
mint f[N],g[N];
int main(){
    n=read();
    for(int i=1;i<=n*2;++i){
        char c;
        while(!isalpha(c=getchar()));
        x=read();
        if(x){
            if(c=='I'){
                if(O[x]){
                    puts("0");
                    return 0;
                }
                I[x]=i;
            }
            else{
                if(!I[x])
                    ++cnt;
                O[x]=i;
            }
        }
        op[i]=c;
        a[i]=x;
    }
    for(int i=1;i<=n*2;++i){
        if(I[a[i]]&&O[a[i]])
            continue;
        ++m;
        op[m]=op[i];
        a[m]=a[i];
    }
    for(int i=1;i<=m;++i){
        if(op[i]=='O')
            pre[i]=pre[i-1]-1;
        else
            pre[i]=pre[i-1]+1;
        if(pre[i]<0){
            puts("0");
            return 0;
        }
    }
    for(int i=m;i;--i){
        sufI[i]=sufI[i+1];
        sufO[i]=sufO[i+1];
        if(op[i]=='O')
            ++sufO[i];
        else
            ++sufI[i];
        isufO[i]=qpow(sufO[i],mod-2);
    }
    f[cnt]=1;
    for(int i=1;i<=m;++i){
        for(int j=0;j<=cnt;++j){
            if(sufI[i]<j){
                g[j]=0;
                continue;
            }
            if(op[i]=='I'){
                if(a[i])
                    g[j]=f[j];
                else
                    g[j]=f[j+1]*(j+1)+f[j]*(sufI[i]-j);
            }
            else{
                if(a[i])
                    g[j]=f[j]*(sufO[i]-j)*isufO[i];
                else if(pre[i-1]>j)
                    g[j]=f[j]*(pre[i-1]-j);
                else
                    g[j]=0;
            }
        }
        for(int j=0;j<=cnt;++j)
            f[j]=g[j];
    }
    printf("%d\n",f[0].x);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3856kb

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: 1ms
memory: 3944kb

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

input:

1
I 0
O 1

output:

1

result:

ok single line: '1'

Test #4:

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

input:

2
I 0
I 1
O 1
O 0

output:

1

result:

ok single line: '1'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3908kb

input:

4
I 0
I 0
O 0
O 0
I 0
I 3
O 0
O 0

output:

96

result:

wrong answer 1st lines differ - expected: '24', found: '96'