結果

問題 No.1492 01文字列と転倒
ユーザー tnakao0123tnakao0123
提出日時 2021-05-03 16:26:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 4,000 ms
コード長 1,338 bytes
コンパイル時間 1,365 ms
コンパイル使用メモリ 90,824 KB
実行使用メモリ 11,592 KB
最終ジャッジ日時 2023-09-29 12:38:00
合計ジャッジ時間 4,888 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,384 KB
testcase_01 AC 6 ms
11,408 KB
testcase_02 AC 332 ms
11,408 KB
testcase_03 AC 297 ms
11,308 KB
testcase_04 AC 274 ms
11,408 KB
testcase_05 AC 235 ms
11,428 KB
testcase_06 AC 245 ms
11,472 KB
testcase_07 AC 265 ms
11,348 KB
testcase_08 AC 317 ms
11,380 KB
testcase_09 AC 8 ms
11,492 KB
testcase_10 AC 5 ms
11,492 KB
testcase_11 AC 6 ms
11,380 KB
testcase_12 AC 6 ms
11,348 KB
testcase_13 AC 6 ms
11,376 KB
testcase_14 AC 246 ms
11,552 KB
testcase_15 AC 12 ms
11,304 KB
testcase_16 AC 21 ms
11,552 KB
testcase_17 AC 237 ms
11,300 KB
testcase_18 AC 23 ms
11,380 KB
testcase_19 AC 10 ms
11,428 KB
testcase_20 AC 19 ms
11,592 KB
testcase_21 AC 203 ms
11,300 KB
testcase_22 AC 22 ms
11,344 KB
testcase_23 AC 17 ms
11,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1492.cc:  No.1492 01文字列と転倒 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_N2 = MAX_N * 2;
const int MAX_NN = MAX_N * MAX_N;

/* typedef */

typedef long long ll;

/* global variables */

int dp[2][MAX_N + 1][MAX_NN + 1];

/* subroutines */

inline void addmod(int &a, int b, int m) { a = (a + b) % m; }

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int n2 = n * 2, nn = n * n;

  dp[0][0][0] = 1;
  int cur = 0, nxt = 1;

  for (int i = 0; i < n2; i++) {
    memset(dp[nxt], 0, sizeof(dp[nxt]));
    int maxj = min(i + 1, n);

    for (int j = 0; j <= n; j++) {
      int zj = i - j;
      for (int k = 0; k <= nn; k++)
	if (dp[cur][j][k]) {
	  // -> 0
	  if (zj < maxj)
	    addmod(dp[nxt][j][k + j], dp[cur][j][k], m);
	  // -> 1
	  if (zj > j && j < maxj)
	    addmod(dp[nxt][j + 1][k], dp[cur][j][k], m);
	}
    }

    swap(cur, nxt);
  }

  for (int k = 0; k <= nn; k++) printf("%d\n", dp[cur][n][k]);
  return 0;
}
0