結果

問題 No.1080 Strange Squared Score Sum
ユーザー beetbeet
提出日時 2020-06-12 23:17:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,104 bytes
コンパイル時間 2,938 ms
コンパイル使用メモリ 204,852 KB
実行使用メモリ 24,052 KB
最終ジャッジ日時 2023-09-06 11:21:15
合計ジャッジ時間 12,155 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
19,344 KB
testcase_01 AC 21 ms
19,320 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 739 ms
19,216 KB
testcase_07 TLE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 1,029 ms
19,228 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 23 ms
19,436 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename M_>
class Enumeration{
  using M = M_;
protected:
  static vector<M> fact,finv,invs;
public:
  static void init(int n){
    n=min<decltype(M::mod)>(n,M::mod-1);

    int m=fact.size();
    if(n<m) return;

    fact.resize(n+1,1);
    finv.resize(n+1,1);
    invs.resize(n+1,1);

    if(m==0) m=1;
    for(int i=m;i<=n;i++) fact[i]=fact[i-1]*M(i);
    finv[n]=M(1)/fact[n];
    for(int i=n;i>=m;i--) finv[i-1]=finv[i]*M(i);
    for(int i=m;i<=n;i++) invs[i]=finv[i]*fact[i-1];
  }

  static M Fact(int n){
    init(n);
    return fact[n];
  }
  static M Finv(int n){
    init(n);
    return finv[n];
  }
  static M Invs(int n){
    init(n);
    return invs[n];
  }

  static M C(int n,int k){
    if(n<k||k<0) return M(0);
    init(n);
    return fact[n]*finv[n-k]*finv[k];
  }

  static M P(int n,int k){
    if(n<k||k<0) return M(0);
    init(n);
    return fact[n]*finv[n-k];
  }

  // put n identical balls into k distinct boxes
  static M H(int n,int k){
    if(n<0||k<0) return M(0);
    if(!n&&!k) return M(1);
    init(n+k);
    return C(n+k-1,n);
  }
};
template<typename M>
vector<M> Enumeration<M>::fact=vector<M>();
template<typename M>
vector<M> Enumeration<M>::finv=vector<M>();
template<typename M>
vector<M> Enumeration<M>::invs=vector<M>();

//INSERT ABOVE HERE
using M = Mint<int, int(1e9+9)>;
const int MAX = 1e5;
M dp[6][MAX]={};
M nx[6][MAX]={};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  using E = Enumeration<M>;
  E::init(1e6);

  int n;
  cin>>n;

  if(n>1.5e4) abort();

  dp[3][1]=M(1);
  dp[4][1]=M(2);
  dp[5][1]=M(1);

  vector<M> ans(n+n+1,0);
  for(int i=1;i<=n+n;i++){
    for(int j=1;j<=i;j++){
      int k=i-j;

      if(j%4==0 or j%4==1)
        ans[k]+=dp[2][j]*E::P(n,n-j);
      else
        ans[k]-=dp[2][j]*E::P(n,n-j);
    }

    for(int j=max(1,i-n-1);j<=i;j++){
      nx[0][j]+=dp[0][j];
      nx[1][j]+=dp[0][j]*M(2);
      nx[2][j]+=dp[0][j];
      nx[1][j]+=dp[1][j];
      nx[2][j]+=dp[1][j];
      nx[2][j]+=dp[2][j];

      nx[0][j]+=dp[3][j];
      nx[1][j]+=dp[3][j]*M(2);
      nx[2][j]+=dp[3][j];
      nx[1][j]+=dp[4][j];
      nx[2][j]+=dp[4][j];
      nx[2][j]+=dp[5][j];

      nx[3][j+1]+=dp[2][j];
      nx[4][j+1]+=dp[2][j]*M(2);
      nx[5][j+1]+=dp[2][j];
    }

    for(int j=1;j<=i;j++)
      for(int t=0;t<6;t++)
        dp[t][j]=nx[t][j],nx[t][j]=0;
  }

  for(int i=1;i<=n;i++) cout<<ans[i]<<newl;
  return 0;
}
0