結果

問題 No.1916 Making Palindrome on Gird
ユーザー lloyzlloyz
提出日時 2023-02-09 00:00:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 440 ms / 3,000 ms
コード長 1,177 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 145,236 KB
最終ジャッジ日時 2023-09-20 13:15:38
合計ジャッジ時間 9,995 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,292 KB
testcase_01 AC 79 ms
70,948 KB
testcase_02 AC 94 ms
76,104 KB
testcase_03 AC 82 ms
71,248 KB
testcase_04 AC 84 ms
75,700 KB
testcase_05 AC 86 ms
75,908 KB
testcase_06 AC 86 ms
75,716 KB
testcase_07 AC 87 ms
75,800 KB
testcase_08 AC 89 ms
75,772 KB
testcase_09 AC 125 ms
84,340 KB
testcase_10 AC 78 ms
71,144 KB
testcase_11 AC 91 ms
76,408 KB
testcase_12 AC 80 ms
74,856 KB
testcase_13 AC 209 ms
101,876 KB
testcase_14 AC 167 ms
93,352 KB
testcase_15 AC 240 ms
109,720 KB
testcase_16 AC 207 ms
101,728 KB
testcase_17 AC 358 ms
137,456 KB
testcase_18 AC 410 ms
144,876 KB
testcase_19 AC 405 ms
145,236 KB
testcase_20 AC 397 ms
137,516 KB
testcase_21 AC 400 ms
137,616 KB
testcase_22 AC 413 ms
144,892 KB
testcase_23 AC 289 ms
136,916 KB
testcase_24 AC 282 ms
137,168 KB
testcase_25 AC 275 ms
136,836 KB
testcase_26 AC 283 ms
137,456 KB
testcase_27 AC 274 ms
137,072 KB
testcase_28 AC 440 ms
137,640 KB
testcase_29 AC 439 ms
137,472 KB
testcase_30 AC 425 ms
137,272 KB
testcase_31 AC 426 ms
137,240 KB
testcase_32 AC 432 ms
137,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
mod = 10**9 + 7

m = (h + w) // 2
DP = [[[0 for _ in range(m)] for _ in range(m)] for _ in range(m)]
for k in range(m - 1, -1, -1):
    for i in range(k + 1):
        for j in range(k + 1):
            a = i
            b = k - i
            c = h - 1 - j
            d = w - 1 - (k - j)
            if 0 <= a < h and 0 <= b < w and 0 <= c < h and 0 <= d < w:
                if S[a][b] != S[c][d]:
                    continue
                if a > c or b > d:
                    continue
                if k == m - 1:
                    DP[i][j][k] = 1
                else:
                    if i < h - 1:
                        if j < h:
                            DP[i][j][k] += DP[i + 1][j + 1][k + 1]
                            DP[i][j][k] %= mod
                        DP[i][j][k] += DP[i + 1][j][k + 1]
                        DP[i][j][k] %= mod
                    if j < h:
                        DP[i][j][k] += DP[i][j + 1][k + 1]
                        DP[i][j][k] %= mod
                    DP[i][j][k] += DP[i][j][k + 1]
                    DP[i][j][k] %= mod
print(DP[0][0][0])
0