QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#610863 | #2271. High-Tech Detective | ucup-team4153# | WA | 0ms | 3624kb | C++20 | 2.5kb | 2024-10-04 17:48:41 | 2024-10-04 17:48:42 |
Judging History
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^
*/
詳細信息
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'