結果

問題 No.1492 01文字列と転倒
ユーザー shotoyooshotoyoo
提出日時 2021-04-25 00:34:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,038 ms / 4,000 ms
コード長 960 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 307,008 KB
最終ジャッジ日時 2023-09-17 13:52:09
合計ジャッジ時間 11,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,308 KB
testcase_01 AC 75 ms
71,312 KB
testcase_02 AC 1,038 ms
304,592 KB
testcase_03 AC 952 ms
305,988 KB
testcase_04 AC 889 ms
307,008 KB
testcase_05 AC 748 ms
287,004 KB
testcase_06 AC 777 ms
297,464 KB
testcase_07 AC 838 ms
301,104 KB
testcase_08 AC 1,013 ms
304,484 KB
testcase_09 AC 75 ms
75,732 KB
testcase_10 AC 73 ms
71,552 KB
testcase_11 AC 73 ms
71,284 KB
testcase_12 AC 71 ms
71,464 KB
testcase_13 AC 72 ms
71,328 KB
testcase_14 AC 768 ms
297,172 KB
testcase_15 AC 82 ms
76,300 KB
testcase_16 AC 96 ms
77,616 KB
testcase_17 AC 736 ms
287,312 KB
testcase_18 AC 96 ms
78,036 KB
testcase_19 AC 82 ms
76,236 KB
testcase_20 AC 92 ms
77,584 KB
testcase_21 AC 646 ms
292,092 KB
testcase_22 AC 98 ms
77,480 KB
testcase_23 AC 88 ms
76,656 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")

s = input()
assert " " in s
# try:
#     input()
# except Exception:
#     pass
# else:
#     assert 0
hoge = input()
assert hoge==""

n,M = list(map(int, s.split()))
assert 1<=n<=100
assert 10**8<=M<=10**9+7

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