結果

問題 No.1667 Forest
ユーザー tko919tko919
提出日時 2021-09-03 23:49:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 932 ms / 3,000 ms
コード長 1,686 bytes
コンパイル時間 4,019 ms
コンパイル使用メモリ 204,020 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 02:12:01
合計ジャッジ時間 9,228 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 932 ms
4,380 KB
testcase_01 AC 922 ms
4,376 KB
testcase_02 AC 906 ms
4,380 KB
testcase_03 AC 10 ms
4,380 KB
testcase_04 AC 895 ms
4,376 KB
testcase_05 AC 532 ms
4,376 KB
testcase_06 AC 326 ms
4,376 KB
testcase_07 AC 200 ms
4,380 KB
testcase_08 AC 97 ms
4,380 KB
testcase_09 AC 57 ms
4,380 KB
testcase_10 AC 29 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

ll mod(ll a,ll m){return (a%m+m)%m;}
ll mpow(ll a,ll t,ll m){
   ll res=1;
   while(t){
      if(t&1)res=mod(res*a,m);
      a=mod(a*a,m); t>>=1;
   } return res;
}
ll minv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; swap(a,b);
      u-=t*v; swap(u,v);
   } u=mod(u,m); return u;
}
int get_root(int p){ //primitive root
   vector<int> ds;
   for(int x=1;x*x<=p-1;x++)if((p-1)%x==0){
      ds.push_back(x);
      if(x*x!=p-1)ds.push_back((p-1)/x);
   }
   sort(ALL(ds));
   ds.pop_back();
   for(int x=1;x<p;x++){
      for(auto& d:ds){
         if(mpow(x,d,p)==1)goto fail;
      }
      return x;
      fail:;
   } assert(0);
}

ll dp[310][310];
ll fact[310],ifac[310],coeff[310];

int main(){
   int n,m;
   cin>>n>>m;
   fact[0]=1;
   rep(x,1,n+1)fact[x]=(fact[x-1]*x)%m;
   ifac[n]=minv(fact[n],m);
   for(int x=n-1;x>=0;x--)ifac[x]=(ifac[x+1]*(x+1))%m;
   coeff[1]=1;
   rep(x,2,n+1)coeff[x]=mpow(x,x-2,m);

   dp[0][0]=1;
   rep(i,0,n){
      rep(j,0,n){
         rep(add,1,n+1)if(i+add<=n){
            dp[i+add][j+1]=(dp[i+add][j+1]+((((dp[i][j]*fact[n-1-i])%m*ifac[add-1])%m*ifac[n-i-add])%m*coeff[add])%m)%m;
         }
      }
   }
   rep(x,0,n){
      cout<<dp[n][n-x]<<'\n';
   }
   return 0;
}
0