結果

問題 No.1492 01文字列と転倒
ユーザー kenskens
提出日時 2021-04-30 21:41:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 997 ms / 4,000 ms
コード長 1,624 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 204,388 KB
実行使用メモリ 18,956 KB
最終ジャッジ日時 2023-09-26 05:33:50
合計ジャッジ時間 11,053 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 984 ms
18,848 KB
testcase_03 AC 903 ms
18,084 KB
testcase_04 AC 803 ms
16,984 KB
testcase_05 AC 667 ms
15,564 KB
testcase_06 AC 720 ms
15,840 KB
testcase_07 AC 791 ms
16,808 KB
testcase_08 AC 997 ms
18,956 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 690 ms
15,884 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 652 ms
15,404 KB
testcase_18 AC 14 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 596 ms
13,864 KB
testcase_22 AC 13 ms
4,376 KB
testcase_23 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
ll mod;

struct mint {
  ll x;
  mint(ll _x = 0) {if((_x %= mod) < 0) _x += mod; x = _x;}
  bool operator==(const mint a) {return x == a.x;}
  mint operator-() const {return mint(-x);}
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const {return pow(mod-2);}
  mint& operator/=(const mint a) {return (*this) *= a.inv();}
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
  ll val() {return x;}
};

int main(){
  int n;
  cin >> n >> mod;
  vector<vector<mint>> dp(n+1,vector<mint>(n*n+1));
  dp[0][0].x = 1;
  rep(i,2*n) {
    vector<vector<mint>> dpn(n+1,vector<mint>(n*n+1));
    int l = min(i+1,n+1);
    rep(j,l) {
      rep(k,n*n+1) {
        if(k+i-j <= n*n and j < n) dpn[j+1][k+i-j] += dp[j][k];
        if(i < 2*j) dpn[j][k] += dp[j][k]; 
      }
    }
    swap(dp,dpn);
  } 
  rep(i,n*n+1) cout << dp[n][i].val() << endl;
  return 0;
}
0