結果

問題 No.1916 Making Palindrome on Gird
ユーザー googol_S0googol_S0
提出日時 2022-04-29 22:06:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,380 ms / 3,000 ms
コード長 764 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 86,724 KB
実行使用メモリ 210,280 KB
最終ジャッジ日時 2023-09-11 13:19:48
合計ジャッジ時間 20,237 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,304 KB
testcase_01 AC 77 ms
71,240 KB
testcase_02 AC 131 ms
77,716 KB
testcase_03 AC 78 ms
71,384 KB
testcase_04 AC 123 ms
77,516 KB
testcase_05 AC 107 ms
77,180 KB
testcase_06 AC 106 ms
77,416 KB
testcase_07 AC 128 ms
77,460 KB
testcase_08 AC 113 ms
77,332 KB
testcase_09 AC 78 ms
71,232 KB
testcase_10 AC 72 ms
71,184 KB
testcase_11 AC 122 ms
77,604 KB
testcase_12 AC 104 ms
76,792 KB
testcase_13 AC 569 ms
120,468 KB
testcase_14 AC 388 ms
110,840 KB
testcase_15 AC 692 ms
135,424 KB
testcase_16 AC 467 ms
104,840 KB
testcase_17 AC 1,159 ms
188,760 KB
testcase_18 AC 1,324 ms
210,280 KB
testcase_19 AC 1,310 ms
209,928 KB
testcase_20 AC 1,291 ms
210,040 KB
testcase_21 AC 1,335 ms
210,048 KB
testcase_22 AC 1,323 ms
210,112 KB
testcase_23 AC 75 ms
71,496 KB
testcase_24 AC 74 ms
71,464 KB
testcase_25 AC 76 ms
71,500 KB
testcase_26 AC 74 ms
71,472 KB
testcase_27 AC 76 ms
71,228 KB
testcase_28 AC 1,360 ms
210,036 KB
testcase_29 AC 1,374 ms
210,004 KB
testcase_30 AC 1,373 ms
210,060 KB
testcase_31 AC 1,380 ms
210,012 KB
testcase_32 AC 1,369 ms
210,160 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
if N==0:
  print(1)
  exit()
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 and x1<=x2 and y1<=y2:
        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