QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244371 | #2271. High-Tech Detective | NYCU_gAwr_gurA# | WA | 1ms | 5620kb | C++20 | 1.7kb | 2023-11-09 00:00:01 | 2023-11-09 00:00:02 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define matsuri pair<int,int>
const int iris = 1e9+7;
//const int iris = 998244353;
using namespace std;
int dp[10001][5001];
char owo[10001];
int arr[10001], cnt[10001], sf[10001], pr[10001], prI[10001], prO[10001];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
for(int i=1;i<=n*2;i++)
{
cin>>owo[i]>>arr[i];
cnt[arr[i]]++;
if(arr[i]==0)
{
if(owo[i]=='I')
pr[i]=1;
else
sf[i]=1;
}
pr[i]+=pr[i-1];
}
for(int i=1;i<=n*2;i++)
{
if(owo[i]=='I' && !(arr[i] && cnt[arr[i]]==2))
prI[i]=1;
if(owo[i]=='O' && !(arr[i] && cnt[arr[i]]==2))
prO[i]=1;
prO[i]+=prO[i-1];
prI[i]+=prI[i-1];
}
for(int i=n*2-1;i>=0;i--)
sf[i]+=sf[i+1];
dp[0][0]=1;
for(int i=1;i<=n*2;i++)
{
if((arr[i] && cnt[arr[i]]==2) || (owo[i]=='I' && arr[i]!=0))
{
for(int j=0;j<=n;j++)
dp[i][j]=dp[i-1][j];
}
else if(owo[i]=='I')
{
for(int j=1;j<=n;j++)
dp[i][j]=dp[i-1][j-1];
}
else if(arr[i])
{
for(int j=0;j<n;j++)
dp[i][j]=dp[i-1][j+1]*(j+1)%iris;
//cout<<'-'<<i<<' '<<'\n';
}
else
{
for(int j=0;j<=n;j++)
{
// prI[i]-prO[i-1]=x+j
int sp=prI[i]-prO[i-1]-j;
//cout<<i<<' '<<sp<<' '<<prI[i]<<' '<<prO[i-1]<<' '<<j<<'\n';
if(j)
{
dp[i][j-1]+=dp[i-1][j]*j%iris*sf[i];
dp[i][j-1]%=iris;
}
dp[i][j]+=dp[i-1][j]*sp;
dp[i][j]%=iris;
}
}
}
for(int i=1;i<=n*2;i++)
{
for(int j=0;j<=n;j++)
{
//cout<<dp[i][j]<<' ';
}
//cout<<'\n';
}
cout<<dp[n*2][0]<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5620kb
input:
4 I 1 I 0 O 0 I 0 O 2 I 4 O 0 O 4
output:
4
result:
wrong answer 1st lines differ - expected: '3', found: '4'