QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#244392 | #2271. High-Tech Detective | NYCU_gAwr_gurA | WA | 1ms | 5680kb | C++20 | 1.6kb | 2023-11-09 01:09:52 | 2023-11-09 01:09:52 |
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];
}
int ooo=0;
for(int i=1;i<=n;i++)
if(cnt[i]==0)
ooo++;
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;
if(j)
{
dp[i][j-1]+=dp[i-1][j]*j;
dp[i][j-1]%=iris;
}
dp[i][j]+=dp[i-1][j]*sp;
dp[i][j]%=iris;
}
}
}
cout<<dp[n*2][0]<<'\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5680kb
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: -100
Wrong Answer
time: 0ms
memory: 3624kb
input:
3 I 0 I 0 I 0 O 0 O 0 O 0
output:
6
result:
wrong answer 1st lines differ - expected: '36', found: '6'