結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | tamato |
提出日時 | 2022-04-29 22:21:24 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,310 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,036 KB |
実行使用メモリ | 93,100 KB |
最終ジャッジ日時 | 2024-06-29 03:55:05 |
合計ジャッジ時間 | 5,436 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,736 KB |
testcase_01 | AC | 37 ms
52,096 KB |
testcase_02 | AC | 47 ms
61,824 KB |
testcase_03 | AC | 33 ms
52,352 KB |
testcase_04 | RE | - |
testcase_05 | AC | 42 ms
61,952 KB |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | AC | 35 ms
52,736 KB |
testcase_10 | AC | 34 ms
52,096 KB |
testcase_11 | RE | - |
testcase_12 | AC | 35 ms
52,864 KB |
testcase_13 | AC | 172 ms
80,220 KB |
testcase_14 | RE | - |
testcase_15 | AC | 180 ms
80,176 KB |
testcase_16 | AC | 156 ms
79,768 KB |
testcase_17 | AC | 260 ms
89,472 KB |
testcase_18 | AC | 284 ms
93,056 KB |
testcase_19 | AC | 281 ms
92,800 KB |
testcase_20 | AC | 289 ms
92,928 KB |
testcase_21 | AC | 301 ms
93,100 KB |
testcase_22 | AC | 282 ms
92,672 KB |
testcase_23 | AC | 35 ms
52,864 KB |
testcase_24 | AC | 33 ms
52,992 KB |
testcase_25 | AC | 34 ms
53,120 KB |
testcase_26 | AC | 34 ms
53,248 KB |
testcase_27 | AC | 32 ms
52,992 KB |
testcase_28 | AC | 265 ms
92,500 KB |
testcase_29 | AC | 277 ms
92,744 KB |
testcase_30 | AC | 278 ms
92,480 KB |
testcase_31 | AC | 278 ms
92,800 KB |
testcase_32 | AC | 283 ms
92,800 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] * W 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] * W 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: 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()