結果

問題 No.1492 01文字列と転倒
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-18 12:07:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,867 ms / 4,000 ms
コード長 563 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 299,928 KB
最終ジャッジ日時 2023-09-04 03:10:49
合計ジャッジ時間 18,747 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,068 KB
testcase_01 AC 77 ms
70,872 KB
testcase_02 AC 1,867 ms
296,340 KB
testcase_03 AC 1,686 ms
296,636 KB
testcase_04 AC 1,558 ms
297,996 KB
testcase_05 AC 1,329 ms
296,520 KB
testcase_06 AC 1,374 ms
299,144 KB
testcase_07 AC 1,486 ms
299,928 KB
testcase_08 AC 1,821 ms
296,644 KB
testcase_09 AC 84 ms
75,916 KB
testcase_10 AC 77 ms
71,264 KB
testcase_11 AC 85 ms
76,168 KB
testcase_12 AC 87 ms
76,196 KB
testcase_13 AC 77 ms
71,188 KB
testcase_14 AC 1,364 ms
299,124 KB
testcase_15 AC 99 ms
76,456 KB
testcase_16 AC 129 ms
78,120 KB
testcase_17 AC 1,318 ms
296,612 KB
testcase_18 AC 130 ms
78,040 KB
testcase_19 AC 94 ms
76,268 KB
testcase_20 AC 117 ms
78,000 KB
testcase_21 AC 1,125 ms
288,800 KB
testcase_22 AC 128 ms
77,988 KB
testcase_23 AC 109 ms
77,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
dp=[[0]*(n**2+1) for _ in range(n+1)]
dp[0][0]=1
# dp[i][j]:num0=i,num1=j
for i in range(2*n):
  ndp=[[0]*(n**2+1) for _ in range(n+1)]
  for j in range(n+1):
    for k in range(n**2+1):
      if dp[j][k]==0:continue
      if j>0:# 1を置く
        ndp[j-1][k]+=dp[j][k]
        ndp[j-1][k]%=m
      if i+j<2*n:# 0を置く
        x1=(i-j)//2
        ndp[j+1][k+x1]+=dp[j][k]
        ndp[j+1][k+x1]%=m
  dp=ndp
ans=[0]*(n**2+1)
for j in range(n+1):
  for k in range(n**2+1):
    ans[k]+=dp[j][k]
    ans[k]%=m
print(*ans,sep='\n')
0