結果

問題 No.1492 01文字列と転倒
ユーザー simansiman
提出日時 2023-01-19 21:24:33
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1,149 ms / 4,000 ms
コード長 957 bytes
コンパイル時間 3,699 ms
コンパイル使用メモリ 102,036 KB
実行使用メモリ 19,268 KB
最終ジャッジ日時 2023-09-04 14:03:06
合計ジャッジ時間 12,880 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1,149 ms
19,268 KB
testcase_03 AC 1,021 ms
18,320 KB
testcase_04 AC 911 ms
17,372 KB
testcase_05 AC 768 ms
15,720 KB
testcase_06 AC 810 ms
16,080 KB
testcase_07 AC 893 ms
16,944 KB
testcase_08 AC 1,118 ms
19,188 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 813 ms
16,176 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 15 ms
4,380 KB
testcase_17 AC 768 ms
15,776 KB
testcase_18 AC 16 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 11 ms
4,384 KB
testcase_21 AC 633 ms
14,168 KB
testcase_22 AC 15 ms
4,380 KB
testcase_23 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;

  ll dp[N + 1][N * N + 1];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;

  for (int i = 0; i < 2 * N; ++i) {
    ll temp[N + 1][N * N + 1];
    memset(temp, 0, sizeof(temp));

    for (int zc = 0; zc <= N; ++zc) {
      int oc = i - zc;
      if (oc > zc) continue;

      for (int k = 0; k < N * N; ++k) {
        if (oc + 1 <= zc) {
          temp[zc][k] += dp[zc][k];
          temp[zc][k] %= M;
        }
        if (zc + 1 <= N) {
          temp[zc + 1][k + oc] += dp[zc][k];
          temp[zc + 1][k + oc] %= M;
        }
      }
    }

    memcpy(dp, temp, sizeof(temp));
  }

  for (int k = 0; k <= N * N; ++k) {
    cout << dp[N][k] << endl;
  }

  return 0;
}
0