QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#727396#9565. Birthday Giftucup-team3646#Compile Error//C++202.8kb2024-11-09 13:06:012024-11-09 13:06:01

Judging History

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

  • [2024-11-09 13:06:01]
  • 评测
  • [2024-11-09 13:06:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, l, r) for(ll i = l; i < r; i++)

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

/* ---- */
#define all(A) A.begin(), A.end()
#define elif else if
using pii = pair<ll, ll>;

bool chmin(auto &a, const auto &b) {return a > b ? a = b, 1 : 0;}
bool chmax(auto &a, const auto &b) {return a < b ? a = b, 1 : 0;}

struct IOSetup {
  IOSetup() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} iosetup;

template<class T>
void print(vector<T> a) {
  for (auto x : a) cerr << x << ' ';
  cerr << endl;
}

void print(auto x) {
  cerr << x << endl;
}

template<class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cerr << head << ' ';
  print(forward<Tail>(tail)...);
}

#include<atcoder/modint>
using namespace atcoder;
using mint=modint998244353;

int table_size=200000;

vector<mint>fac(table_size+1,1),finv(table_size+1,1);

void calc_binom_table(){
  for(int i=2;i<=table_size;i++){
    fac[i]=fac[i-1]*i;
  }
  finv[table_size]=fac[table_size].inv();
  for(int i=table_size-1;i>=0;i--){
    finv[i]=finv[i+1]*(i+1);
  }
}

mint binom(int n,int k){
  if(n<0||k<0||k>n)return 0;
  return fac[n]*finv[k]*finv[n-k];
}

vector<vector<int>> G;
int N;

vector<vector<mint>> DP;
vector<int> C;
vector<mint> F;
bool deb=1;

void predfs(int p){
  F[p]=1;
  for(int n:G[p]){
    predfs(n);
    C[p]+=C[n];
    F[p]*=F[n];
    F[p]*=finv[C[n]];
  }
  F[p]*=fac[C[p]];
  C[p]++;
}

void dfs(int p){
  cout<<p<<endl;
  for(int i=0;i<N;i++)DP[p][i+1]+=DP[p][i];

  int pn=G[p].size();
  vector<mint> LJ(pn+1,1),RJ(pn+1,1);
  for(int i=0;i<pn;i++){
    LJ[i+1]=LJ[i]*F[G[p][i]]*finv[C[G[p][i]]];
  }
  for(int i=N-1;i>=0;i--){
    RJ[i]=RJ[i+1]*F[G[p][i]]*finv[C[G[p][i]]];
  }

  int T=0;
  for(int n:G[p])T+=C[n];

  for(int i=0;i<pn;i++){
    int n=G[p][i];
    int t=T-C[n];
    mint J=LJ[i]*RJ[i+1]*fac[t];
    for(int k=0;k<=N;k++){
      int z=N-C[p]-k;
      if(z<0)continue;
      if(k+1<=N)DP[n][k+1]+=DP[p][k]*J*binom(z+t,t);
      if(k+z+t+2<=N)DP[n][k+z+t+2]-=DP[p][k]*J*binom(z+t,t);
    }

    dfs(n);
  }
}

int main(){
  calc_binom_table();

  cin>>N;
  G.resize(N);
  for(int i=0;i<N-1;i++){
    int p;
    cin>>p;
    p--;
    G[p].push_back(i+1);
  }

  DP.assign(N,vector<mint>(N+1,0));
  C.assign(N,0);
  F.assign(N,0);
  if(deb)cout<<"step1"<<endl;
  predfs(0);

  if(deb)cout<<"setp2"<<endl;
  DP[0][0]=1;
  DP[0][1]=-1;
  dfs(0);
  if(deb)cout<<"step3"<<endl;

  for(int i=0;i<N;i++){
    mint an=DP[i][i]*F[i];
    int z=N-C[i]-i;
    an*=binom(z+C[i]-1,z);
    cout<<an.val()<<" \n"[i==N-1];
  }



}
dummy

Details

answer.code:43:9: fatal error: atcoder/modint: No such file or directory
   43 | #include<atcoder/modint>
      |         ^~~~~~~~~~~~~~~~
compilation terminated.