結果

問題 No.1916 Making Palindrome on Gird
ユーザー googol_S0googol_S0
提出日時 2022-04-29 22:03:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 713 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 210,352 KB
最終ジャッジ日時 2023-09-11 13:16:08
合計ジャッジ時間 21,281 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,424 KB
testcase_01 AC 73 ms
71,128 KB
testcase_02 AC 130 ms
78,004 KB
testcase_03 WA -
testcase_04 AC 124 ms
77,592 KB
testcase_05 AC 107 ms
77,424 KB
testcase_06 AC 108 ms
77,472 KB
testcase_07 AC 129 ms
77,600 KB
testcase_08 AC 109 ms
77,400 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 122 ms
77,768 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 393 ms
110,904 KB
testcase_15 WA -
testcase_16 AC 473 ms
104,888 KB
testcase_17 AC 1,161 ms
188,788 KB
testcase_18 AC 1,327 ms
210,352 KB
testcase_19 AC 1,317 ms
210,048 KB
testcase_20 AC 1,316 ms
210,348 KB
testcase_21 AC 1,332 ms
210,156 KB
testcase_22 AC 1,340 ms
210,008 KB
testcase_23 AC 75 ms
71,328 KB
testcase_24 AC 76 ms
71,428 KB
testcase_25 AC 75 ms
71,548 KB
testcase_26 AC 76 ms
71,364 KB
testcase_27 AC 76 ms
71,544 KB
testcase_28 AC 1,371 ms
210,272 KB
testcase_29 AC 1,372 ms
210,068 KB
testcase_30 AC 1,365 ms
210,072 KB
testcase_31 AC 1,383 ms
210,340 KB
testcase_32 AC 1,379 ms
210,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7
H,W=map(int,input().split())
S=[input() for i in range(H)]
if S[0][0]!=S[-1][-1]:
  print(0)
  exit()
N=H+W-2
DP=[[[0]*H for i in range(H)] for j in range(N+1)]
DP[0][0][H-1]=1
ANS=0
for i in range(N):
  for j in range(H):
    for k in range(H):
      x1,y1=j,i-j
      x2,y2=k,W-1-(i-(H-1-k))
      if y1<0 or y2<0 or y2>=W:
        continue
      if abs(x1-x2)+abs(y1-y2)<=1:
        ANS=(ANS+DP[i][j][k])%mod
      for l in range(2):
        for m in range(2):
          x3,y3=x1+l,y1+(l^1)
          x4,y4=x2-m,y2-(m^1)
          if H<=x3 or W<=y3 or x4<0 or y4<0:
            continue
          if S[x3][y3]==S[x4][y4]:
            DP[i+1][j+l][k-m]=(DP[i+1][j+l][k-m]+DP[i][j][k])%mod
print(ANS)
0