結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | tktk_snsn |
提出日時 | 2022-04-29 23:15:17 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,656 bytes |
コンパイル時間 | 262 ms |
コンパイル使用メモリ | 87,140 KB |
実行使用メモリ | 181,244 KB |
最終ジャッジ日時 | 2023-09-11 14:46:44 |
合計ジャッジ時間 | 15,481 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
71,348 KB |
testcase_01 | AC | 87 ms
71,260 KB |
testcase_02 | AC | 116 ms
77,364 KB |
testcase_03 | AC | 87 ms
71,176 KB |
testcase_04 | AC | 87 ms
71,304 KB |
testcase_05 | AC | 88 ms
71,160 KB |
testcase_06 | AC | 90 ms
71,372 KB |
testcase_07 | AC | 90 ms
71,324 KB |
testcase_08 | AC | 89 ms
71,512 KB |
testcase_09 | AC | 87 ms
71,336 KB |
testcase_10 | WA | - |
testcase_11 | AC | 90 ms
71,772 KB |
testcase_12 | AC | 87 ms
71,348 KB |
testcase_13 | AC | 110 ms
77,428 KB |
testcase_14 | AC | 110 ms
77,080 KB |
testcase_15 | AC | 209 ms
78,552 KB |
testcase_16 | AC | 196 ms
78,576 KB |
testcase_17 | AC | 288 ms
80,972 KB |
testcase_18 | AC | 723 ms
107,072 KB |
testcase_19 | AC | 679 ms
105,196 KB |
testcase_20 | AC | 684 ms
105,748 KB |
testcase_21 | AC | 676 ms
106,468 KB |
testcase_22 | AC | 669 ms
105,972 KB |
testcase_23 | AC | 87 ms
71,424 KB |
testcase_24 | AC | 86 ms
71,992 KB |
testcase_25 | AC | 88 ms
71,536 KB |
testcase_26 | AC | 92 ms
71,968 KB |
testcase_27 | AC | 92 ms
71,980 KB |
testcase_28 | AC | 1,542 ms
181,244 KB |
testcase_29 | AC | 1,541 ms
180,320 KB |
testcase_30 | AC | 1,558 ms
180,892 KB |
testcase_31 | AC | 1,534 ms
180,412 KB |
testcase_32 | AC | 1,536 ms
180,768 KB |
ソースコード
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: finish = False update = 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 id(x, y, xx, yy) != id(nnx, nny, nx, ny): 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 ans = 0 for k, v in dp.items(): ans += v ans %= mod print(ans)