結果

問題 No.1492 01文字列と転倒
ユーザー shotoyooshotoyoo
提出日時 2021-04-25 00:31:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,033 ms / 4,000 ms
コード長 933 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 306,676 KB
最終ジャッジ日時 2023-09-17 13:50:52
合計ジャッジ時間 10,962 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,468 KB
testcase_01 AC 75 ms
71,200 KB
testcase_02 AC 1,033 ms
304,084 KB
testcase_03 AC 950 ms
305,268 KB
testcase_04 AC 870 ms
306,676 KB
testcase_05 AC 733 ms
287,272 KB
testcase_06 AC 775 ms
297,352 KB
testcase_07 AC 837 ms
300,968 KB
testcase_08 AC 1,022 ms
304,528 KB
testcase_09 AC 80 ms
75,724 KB
testcase_10 AC 72 ms
71,448 KB
testcase_11 AC 73 ms
71,136 KB
testcase_12 AC 72 ms
71,420 KB
testcase_13 AC 74 ms
71,468 KB
testcase_14 AC 777 ms
297,208 KB
testcase_15 AC 84 ms
76,420 KB
testcase_16 AC 97 ms
77,572 KB
testcase_17 AC 741 ms
287,232 KB
testcase_18 AC 97 ms
78,152 KB
testcase_19 AC 80 ms
76,328 KB
testcase_20 AC 93 ms
77,500 KB
testcase_21 AC 642 ms
291,736 KB
testcase_22 AC 96 ms
77,900 KB
testcase_23 AC 88 ms
76,788 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
    
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