結果
問題 |
No.1916 Making Palindrome on Gird
|
ユーザー |
![]() |
提出日時 | 2022-04-29 23:09:38 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,717 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 82,564 KB |
実行使用メモリ | 181,572 KB |
最終ジャッジ日時 | 2024-06-29 04:52:36 |
合計ジャッジ時間 | 14,310 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 WA * 1 |
ソースコード
from collections import Counter from collections import defaultdict mod = 10 ** 9 + 7 U = 201 H, W = map(int, input().split()) G = [input() for _ in range(H)] def id(x, y, xx, yy): res = x res = res * U + y res = res * U + xx res = res * U + yy return res def parse(m): m, yy = divmod(m, U) m, xx = divmod(m, U) x, y = divmod(m, U) return x, y, xx, yy if G[0][0] != G[H-1][W-1]: print(0) exit() dp = defaultdict(int) dp[id(0, 0, H-1, W-1)] = 1 while True: update = False finish = False ndp = defaultdict(int) for k, v in dp.items(): x, y, xx, yy = parse(k) for di, dj in [(0, 1), (1, 0)]: nx = x + di ny = y + dj if nx < 0 or nx >= H or ny < 0 or ny >= W: continue for ddi, ddj in [(0, -1), (-1, 0)]: nnx = xx + ddi nny = yy + ddj if nnx < 0 or nnx >= H or nny < 0 or nny >= W: continue if G[nx][ny] != G[nnx][nny]: continue if (nx + ny) >= (nnx + nny): finish = True if (H + W - 1) % 2 == 1 and (nx, ny) != (nnx, nny): continue if (H + W - 1) % 2 == 0 and ((x, y) != (nnx, nny) or (nx, ny) != (xx, yy)): continue ndp[id(nx, ny, nnx, nny)] += v ndp[id(nx, ny, nnx, nny)] %= mod update = True dp = ndp if finish: break if not update: break if not finish: print(0) else: ans = 0 for k, v in dp.items(): ans += v ans %= mod print(ans)