結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | tamato |
提出日時 | 2022-04-29 22:24:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 299 ms / 3,000 ms |
コード長 | 2,366 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 93,140 KB |
最終ジャッジ日時 | 2024-06-29 03:59:23 |
合計ジャッジ時間 | 5,610 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
53,448 KB |
testcase_01 | AC | 33 ms
53,224 KB |
testcase_02 | AC | 43 ms
62,320 KB |
testcase_03 | AC | 33 ms
53,144 KB |
testcase_04 | AC | 47 ms
64,752 KB |
testcase_05 | AC | 45 ms
62,772 KB |
testcase_06 | AC | 43 ms
62,436 KB |
testcase_07 | AC | 45 ms
62,472 KB |
testcase_08 | AC | 49 ms
64,904 KB |
testcase_09 | AC | 36 ms
53,972 KB |
testcase_10 | AC | 33 ms
52,868 KB |
testcase_11 | AC | 46 ms
61,708 KB |
testcase_12 | AC | 34 ms
52,880 KB |
testcase_13 | AC | 179 ms
80,048 KB |
testcase_14 | AC | 137 ms
78,412 KB |
testcase_15 | AC | 183 ms
79,956 KB |
testcase_16 | AC | 156 ms
78,152 KB |
testcase_17 | AC | 267 ms
89,556 KB |
testcase_18 | AC | 289 ms
92,864 KB |
testcase_19 | AC | 277 ms
93,140 KB |
testcase_20 | AC | 282 ms
92,808 KB |
testcase_21 | AC | 286 ms
93,076 KB |
testcase_22 | AC | 299 ms
92,776 KB |
testcase_23 | AC | 34 ms
53,264 KB |
testcase_24 | AC | 37 ms
52,972 KB |
testcase_25 | AC | 37 ms
53,980 KB |
testcase_26 | AC | 36 ms
53,016 KB |
testcase_27 | AC | 36 ms
53,372 KB |
testcase_28 | AC | 277 ms
92,700 KB |
testcase_29 | AC | 284 ms
92,484 KB |
testcase_30 | AC | 262 ms
92,328 KB |
testcase_31 | AC | 264 ms
92,440 KB |
testcase_32 | AC | 276 ms
92,496 KB |
ソースコード
mod = 1000000007 def main(): import sys input = sys.stdin.readline H, W = map(int, input().split()) G = [] for _ in range(H): G.append(input().rstrip('\n')) dp = [[0] * H for _ in range(H)] if G[0][0] != G[-1][-1]: print(0) exit() dp[0][H-1] = 1 for hw in range((H + W - 2) // 2): dp_new = [[0] * H for _ in range(H)] for hl in range(H): wl = hw - hl if wl < 0 or wl >= W: continue for hr in range(H): wr = H + W - 2 - hw - hr if wr < 0 or wr >= W: continue if hl != H - 1: hl_new = hl + 1 sl = G[hl_new][wl] if hr != 0: hr_new = hr - 1 sr = G[hr_new][wr] if sl == sr: dp_new[hl_new][hr_new] = (dp_new[hl_new][hr_new] + dp[hl][hr])%mod if wr != 0: wr_new = wr - 1 sr = G[hr][wr_new] if sl == sr: dp_new[hl_new][hr] = (dp_new[hl_new][hr] + dp[hl][hr]) % mod if wl != W - 1: hl_new = hl sl = G[hl_new][wl+1] if hr != 0: hr_new = hr - 1 sr = G[hr_new][wr] if sl == sr: dp_new[hl_new][hr_new] = (dp_new[hl_new][hr_new] + dp[hl][hr]) % mod if wr != 0: wr_new = wr - 1 sr = G[hr][wr_new] if sl == sr: dp_new[hl_new][hr] = (dp_new[hl_new][hr] + dp[hl][hr]) % mod dp = dp_new if (H + W) & 1: ans = 0 for hl in range(H): wl = (H + W - 2) // 2 - hl for hr in range(H): wr = (H + W - 2) // 2 + 1 - hr if abs(hl - hr) + abs(wl - wr) == 1: if 0 <= wl < W and 0 <= wr < W: ans = (ans + dp[hl][hr])%mod print(ans) else: ans = 0 for hl in range(H): ans = (ans + dp[hl][hl])%mod print(ans) if __name__ == '__main__': main()