QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133782#4939. Red Black BallRd_rainydaysCompile Error//C++203.2kb2023-08-02 14:00:042023-08-02 14:00:07

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 14:00:07]
  • 评测
  • [2023-08-02 14:00:04]
  • 提交

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];
int n;
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 n=v[x].size();
  for(int i=1;i<=n;i++)tmp[i]=v[x][i-1];
  for(int i=1;i<=n;i++)for(int r=1;r<=n;r++)vis[i][r]=col[i]=0;
  for(int i=1;i<=n;i++)for(int r=1;r<=n;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

answer.code:41:5: error: redefinition of ‘int n’
   41 | int n,m;
      |     ^
answer.code:13:5: note: ‘int n’ previously declared here
   13 | int n;
      |     ^
answer.code: In function ‘int main()’:
answer.code:90:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   90 |   scanf("%d%d",&n,&m);
      |   ~~~~~^~~~~~~~~~~~~~
answer.code:92:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   92 |     scanf("%d%s",&lib[i].x,s+1);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
answer.code:102:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  102 |     scanf("%d",&x);
      |     ~~~~~^~~~~~~~~