QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133794 | #4939. Red Black Ball | Rd_rainydays | WA | 1ms | 5796kb | C++20 | 3.2kb | 2023-08-02 14:03:25 | 2023-08-02 14:03:29 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
#define N 55
#define M 200005
using namespace std;
const ll mod=998244353;
ll dp[N][N][N*2];
ll DP[N][N*2];
ll fac[M],inv[M];
ll qpow(ll a,ll b){
ll ans=1;
for(;b;b>>=1,a=a*a%mod)if(b&1)ans=ans*a%mod;
return ans;
}
void init(){
fac[1]=1;
for(int i=1;i<=200000;i++)fac[i]=fac[i-1]*i%mod;
inv[200000]=qpow(fac[200000],mod-2);
for(int i=200000;i>=1;i--)inv[i-1]=inv[i]*i%mod;
}
ll C(int n,int m){
if(n<m)return 0;
return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
ll A(int n,int m){
if(n<m)return 0;
return fac[n]*inv[n-m]%mod;
}
char s[122];
vector<int> v[N];
struct zero{
int x,op;
friend bool operator<(zero a,zero b){return a.x<b.x;}
}lib[N];
int kl[N];
int n,m;
int rain_sum=0;
int tmp[N];
int vis[N][N];
int col[N];
void dfs(int l,int r){
if(l==r){
if(tmp[l+1]-tmp[l]<tmp[l]-tmp[l-1])dp[l][r][50+(col[l+1]==1)?-1:1]=1,col[l]=col[l+1];
else dp[l][r][50+(col[l-1]==1)?-1:1]=1,col[l]=col[l-1];
return;
}
if(vis[l][r])return;
vis[l][r]=1;
for(int i=l;i<=r;i++){
if(tmp[r+1]-tmp[i]<tmp[i]-tmp[l-1]){
col[i]=col[r+1];
int kl=r-i+1;
dfs(l,i-1);
for(int p=50-(i-l);p<=50+(i-l);p++){
dp[l][r][p+(col[i]==1?-1:1)*kl]+=dp[l][i-1][p]*A(r-l,r-i)%mod;
}
}
else{
col[i]=col[l-1];
int kl=i-l+1;
dfs(i+1,r);
for(int p=50-(r-i);p<=50+(r-i);p++){
dp[l][r][p+(col[i]==1?-1:1)*kl]+=dp[l][i-1][p]*A(r-l,i-l)%mod;
}
}
}
col[l]=0;
}
void solve(int x){
sort(v[x].begin(),v[x].end());
int len=v[x].size();
for(int i=1;i<=len;i++)tmp[i]=v[x][i-1];
for(int i=1;i<=len;i++)for(int r=1;r<=len;r++)vis[i][r]=col[i]=0;
for(int i=1;i<=len;i++)for(int r=1;r<=len;r++)for(int k=0;k<=100;k++)dp[i][r][k]=0;
tmp[0]=lib[x].x;
tmp[n+1]=lib[x+1].x;
col[0]=lib[x].op;
col[n+1]=lib[x+1].op;
dfs(1,n);
for(int i=0;i<=100;i++)DP[x][i]=dp[1][n][i];
}
int key[N];
ll final_ans[N*2];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d%s",&lib[i].x,s+1);
if(s[1]=='R')lib[i].op=0;
else lib[i].op=1;
}
sort(lib+1,lib+n+1);
for(int i=1;i<=n;i++)kl[i]=lib[i].x;
kl[0]=-100;
kl[n+1]=1000000007;
for(int i=1;i<=m;i++){
int x;
scanf("%d",&x);
int id=lower_bound(kl,kl+n+2,x)-kl;
v[id].push_back(x);
}
ll aux_sum=0;
aux_sum+=v[0].size()+v[n].size();
rain_sum=50;
if(lib[0].op==0)rain_sum+=v[0].size();
else rain_sum-=v[0].size();
if(lib[n].op==0)rain_sum+=v[n].size();
else rain_sum-=v[n].size();
for(int i=1;i<n;i++){
if(lib[i].op==lib[i+1].op){
aux_sum+=v[i].size();
if(lib[i].op==0)rain_sum+=v[i].size();
else rain_sum-=v[i].size();
}
else {key[i]=1;solve(i);}
}
final_ans[50+rain_sum]=fac[aux_sum];
for(int i=1;i<n;i++){
if(!key[i])continue;
for(int r=0;r<=100;r++)
for(int k=-50;k<=50;k++){
if(r+k>=0&&r+k<=100)final_ans[r+k]=final_ans[r]*DP[i][k+50]%mod*C(aux_sum+v[i].size(),v[i].size())%mod;
}
}
ll rain_ans=0;
for(int i=51;i<=100;i++)rain_ans+=final_ans[i];
printf("%lld\n",rain_ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5796kb
input:
2 3 1 BLACK 10 RED 2 5 7
output:
0
result:
wrong answer 1st lines differ - expected: '3', found: '0'