結果

問題 No.1492 01文字列と転倒
ユーザー snow39snow39
提出日時 2021-04-30 21:29:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,063 ms / 4,000 ms
コード長 1,179 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 108,868 KB
実行使用メモリ 18,856 KB
最終ジャッジ日時 2023-09-26 04:28:52
合計ジャッジ時間 10,363 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1,021 ms
18,856 KB
testcase_03 AC 972 ms
18,136 KB
testcase_04 AC 900 ms
16,960 KB
testcase_05 AC 706 ms
15,388 KB
testcase_06 AC 713 ms
15,704 KB
testcase_07 AC 827 ms
16,684 KB
testcase_08 AC 1,063 ms
18,844 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 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 757 ms
15,704 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 717 ms
15,376 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 600 ms
13,776 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  ll M;
  cin>>N>>M;

  int all=2*N;
  vector<vector<ll>> dp(N+1,vector<ll> (N*N+1,0));
  dp[0][0]=1;
  for(int i=0;i<all;i++){
    vector<vector<ll>> ndp(N+1,vector<ll> (N*N+1,0));
    for(int j=0;j<=N;j++){
      for(int k=0;k<=N*N;k++){
        ll value=dp[j][k];
        if(value==0) continue;

        int zero=j,one=i-j;
        if(zero+1<=N){// 0
          ndp[zero+1][k+one]+=value;
          ndp[zero+1][k+one]%=M;
        }
        if(zero>=one+1){
          ndp[zero][k]+=value;
          ndp[zero][k]%=M;
        }
      }
    }
    swap(dp,ndp);
  }

  rep(k,N*N+1){
    cout<<dp[N][k]<<"\n";
  }

  return 0;
}
0