QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#515445#2271. High-Tech Detectiveurayaha_yahaura#WA 0ms3908kbC++142.8kb2024-08-11 17:52:252024-08-11 17:52:26

Judging History

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

  • [2024-08-11 17:52:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3908kb
  • [2024-08-11 17:52:25]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
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 preI[N],preO[N],sufI[N],sufO[N],isufO[N];
mint f[N],g[N];
signed main(){
    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){
        preI[i]=preI[i-1];
        preO[i]=preO[i-1];
        if(op[i]=='O')
           ++preO[i];
        else
           ++preI[i];
        if(preI[i]<preO[i]){
            puts("0");
            return 0;
        }
    }
    for(int i=m;i;--i){
        sufI[i]=sufI[i+1];
        sufO[i]=sufO[i+1];
        if(op[i]=='O'&&a[i])
            ++sufO[i];
        else if(op[i]=='I'&&!a[i])
            ++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]){
                    if(sufO[i]>j)
                        g[j]=f[j]*(sufO[i]-j)*isufO[i];
                    else
                        g[j]=0;
                }
                else{
                    if(preI[i-1]-preO[i-1]>sufO[i]-j)
                        g[j]=f[j]*(preI[i-1]-preO[i-1]-sufO[i]+j);
                    else
                        g[j]=0;
                }
            }
        }
        for(int j=0;j<=cnt;++j)
            f[j]=g[j];
    }
    printf("%lld\n",(f[0].x%mod+mod)%mod);
    return 0;
}

詳細信息

Test #1:

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

input:

4
I 1
I 0
O 0
I 0
O 2
I 4
O 0
O 4

output:

1

result:

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