QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610863#2271. High-Tech Detectiveucup-team4153#WA 0ms3624kbC++202.5kb2024-10-04 17:48:412024-10-04 17:48:42

Judging History

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

  • [2024-10-04 17:48:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-10-04 17:48:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;using ld=long double;using ll=long long;
using pll=pair<ll,ll>;using pii=pair<int,int>;
const int M=1e9+7,inv2=(M+1)/2,P=20;const ld eps=1e-8,pi=acos(-1);
ll poww(ll bs,ll x){ll res=1;for(;x;x>>=1,(bs*=bs)%=M)if(x&1)(res*=bs)%=M;return res;}
ll invv(ll bs){return poww(bs,M-2);}
void add(ll&a,ll b){a+=b;if(a>=M)a-=M;}
struct S
{
    int n,nd=0,mx=0,sp;vector<pii>a;
    vector<vector<int>>tim;
    void ini()
    {
        cin>>n;string s;map<int,int>mp;tim.resize(2,vector<int>(n+1,-1));
        vector<pii>b(n*2);int tc=0;
        for(auto&[x,y]:b)
        {
            cin>>s>>x,y=(s[0]=='O'),mp[x]++;
            tim[y][x]=++tc;
        }

        for(auto&k:b)
        {
            auto[x,y]=k;if(x&&mp[x]==2){nd++;continue;}
            a.push_back({bool(x),y});
        }

    }
    void solve()
    {
        for(int i=1;i<=n;i++)
        {
            int x=tim[0][i],y=tim[1][i];
            if(x==-1&&y==-1)sp++;
            else if(x!=-1&&y!=-1)
            {
                if(x>y){cout<<"0\n";return;}
            }
        }
        n-=nd/2;
        //cout<<n<<"&"<<sp<<'\n';
        vector<ll>dp(n+2,0);dp[0]=1;//free I_cnt
        for(int i=1,Ic=0;i<=n*2;i++)
        {
            auto [v,sta]=a[i-1];vector<ll>dp2(n+2,0);
            //cout<<v<<'/'<<sta<<'/'<<i<<'\n';
            if(sta==0)//I
            {
                Ic++;
                if(v==1)
                {
                    for(int i=0;i<=Ic;i++)dp2[i]=dp[i];
                }
                else
                {
                    for(int i=1;i<=Ic;i++)dp2[i]=dp[i-1];
                }
            }
            else
            {
                if(Ic==0){cout<<"0\n";return;}
                for(int i=0;i<=Ic;i++)if(i)dp2[i-1]=dp[i]*i%M;
                if(v==0)
                {
                    for(int i=0;i<=Ic;i++)add(dp2[i],dp[i]*(Ic-i)%M);
                }
                Ic--;
            }
            swap(dp,dp2);
            //cout<<Ic<<"|";
            //for(int i=0;i<=n;i++)cout<<dp[i]<<".\n"[i==n];
        }
        ll res=0;for(auto&k:dp)add(res,k);

        for(int i=1;i<=sp;i++)(res*=i)%=M;
        cout<<res<<'\n';
    }
};
signed main()
{
    cout<<fixed<<setprecision(12);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;//cin>>t;
    while(t--){S SS;SS.ini();SS.solve();}
}
/*
1274368 996265816
1807139^
1274369 996265816
1165429^
1274369 996269373
inf^
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

883495139

result:

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