QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#535456 | #9128. Priority Queue 3 | dlwlrma | WA | 1ms | 6008kb | C++14 | 2.1kb | 2024-08-28 03:22:18 | 2024-08-28 03:22:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=998244353;
int n,m;
ll C[305][305];
ll dp[305][305];//ways to clear [i,j] such that i is the last cleared
int a[305];//number of + with at most i - following it
int pa[305];
int y[305];
ll dp2[305][305];//ways to fill 1-i such that the suffix j guys are cleared
int main(){
ios::sync_with_stdio(false);cin.tie(0);
freopen("in.txt","r",stdin);
cin >> n >> m;
for(int i=0; i<=n ;i++){
C[i][0]=1;
for(int j=1; j<=i ;j++){
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
}
string s;cin >> s;
int frog=0;
for(int i=s.size()-1; i>=0 ;i--){
if(s[i]=='-') frog++;
else a[frog]++;
}
pa[0]=a[0];
for(int i=1; i<=m ;i++) pa[i]=pa[i-1]+a[i];
for(int i=0; i<=m ;i++)
for(int i=1; i<=m ;i++){
int x;cin >> x;y[x]=1;
}
for(int i=0; i<=m ;i++) cout << a[i] << ' ';
cout << endl;
for(int i=1; i<=n ;i++)y[i]+=y[i-1];
for(int i=m; i>=1 ;i--){
for(int j=i; j<=m ;j++){
for(int k=i+1; k<=j ;k++){//2nd last guy that got killed
ll w1=dp[i][k-1];
ll w2=dp[k][j]*(pa[j]-pa[k-1]-(j-k))%mod;
ll w3=C[j-i-1][j-k];
dp[i][j]=(dp[i][j]+w1*w2%mod*w3)%mod;
}
if(i==j) dp[i][j]=1;
}
}
for(int i=m; i>=1 ;i--){
for(int j=i; j<=m ;j++){
dp[i][j]=dp[i][j]*(pa[j]-pa[i-1]-(j-i))%mod;
//cout << "hi " << i << ' ' << j << ' ' << dp[i][j] << endl;
}
}
dp2[0][0]=1;
for(int r=1; r<=n ;r++){
if(y[r]==y[r-1]){//rotting in queue
for(int j=0; j<r ;j++){
int space=pa[j]-(r-y[r]-1)-j;
space=max(space,0);
dp2[r][j]=dp2[r-1][j]*space%mod;
//cout << "dp2 " << r << ' ' << j << ' ' << dp2[r][j] << endl;
}
continue;
}
for(int j=0; j<r ;j++){
dp2[r][j]=(dp2[r][j]+dp2[r-1][j])%mod;//not fancy
for(int k=j+1; k<=r ;k++){//fancy
if(y[r]<k) break;
ll ways=C[y[r]-j-1][k-j-1]*dp[j+1][k]%mod;
dp2[r][k]=(dp2[r][k]+dp2[r-1][j]*ways)%mod;
}
}
//for(int j=0; j<=r ;j++) cout << "dp2 " << r << ' ' << j << ' ' << dp2[r][j] << endl;
}
cout << dp2[n][m] << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6008kb
input:
4 2 ++-++- 1 3
output:
0 1
result:
wrong answer 1st words differ - expected: '4', found: '0'