結果

問題 No.1492 01文字列と転倒
ユーザー shotoyooshotoyoo
提出日時 2021-03-30 22:19:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 913 ms / 4,000 ms
コード長 788 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 86,604 KB
実行使用メモリ 306,524 KB
最終ジャッジ日時 2023-08-26 14:29:01
合計ジャッジ時間 9,980 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
70,920 KB
testcase_01 AC 62 ms
70,876 KB
testcase_02 AC 913 ms
304,064 KB
testcase_03 AC 838 ms
305,456 KB
testcase_04 AC 781 ms
306,524 KB
testcase_05 AC 653 ms
286,820 KB
testcase_06 AC 697 ms
295,368 KB
testcase_07 AC 751 ms
300,440 KB
testcase_08 AC 902 ms
304,020 KB
testcase_09 AC 67 ms
75,212 KB
testcase_10 AC 63 ms
70,932 KB
testcase_11 AC 64 ms
70,996 KB
testcase_12 AC 64 ms
70,924 KB
testcase_13 AC 66 ms
70,868 KB
testcase_14 AC 676 ms
294,888 KB
testcase_15 AC 75 ms
75,792 KB
testcase_16 AC 86 ms
77,384 KB
testcase_17 AC 682 ms
286,712 KB
testcase_18 AC 87 ms
77,892 KB
testcase_19 AC 75 ms
75,796 KB
testcase_20 AC 85 ms
77,116 KB
testcase_21 AC 562 ms
291,560 KB
testcase_22 AC 85 ms
77,204 KB
testcase_23 AC 75 ms
76,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")

n,M = list(map(int, input().split()))
dp = [[0]*(n*n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(2*n):
    # i: すでに置かれている個数
    ndp = [[0]*(n*n+1) for _ in range(n+1)]
    for j in range((i+1)//2, min(i, n)+1):
        for k in range(min(i*i, n*n)+1):
            if dp[j][k]==0:
                continue
            if j>=(i+1)//2:
                ndp[j][k] += dp[j][k]
                ndp[j][k] %= M
            if j+1<=n:
                ndp[j+1][k+i-j] += dp[j][k]
                ndp[j+1][k+i-j] %= M
    dp = ndp
#     print(dp)
ans = dp[n]
write("\n".join(map(str, ans)))
0