結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | wolgnik |
提出日時 | 2022-04-29 22:02:37 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,306 bytes |
コンパイル時間 | 298 ms |
コンパイル使用メモリ | 87,028 KB |
実行使用メモリ | 843,328 KB |
最終ジャッジ日時 | 2023-09-11 13:13:12 |
合計ジャッジ時間 | 4,161 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
71,492 KB |
testcase_01 | AC | 73 ms
71,460 KB |
testcase_02 | AC | 149 ms
78,280 KB |
testcase_03 | AC | 95 ms
71,556 KB |
testcase_04 | AC | 102 ms
72,904 KB |
testcase_05 | AC | 103 ms
73,168 KB |
testcase_06 | AC | 101 ms
72,920 KB |
testcase_07 | AC | 102 ms
72,976 KB |
testcase_08 | AC | 102 ms
73,116 KB |
testcase_09 | AC | 99 ms
72,908 KB |
testcase_10 | AC | 93 ms
71,772 KB |
testcase_11 | AC | 108 ms
78,000 KB |
testcase_12 | AC | 100 ms
72,484 KB |
testcase_13 | MLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
import sys input = sys.stdin.readline H, W = map(int, input().split()) a = [list(input())[: -1] for _ in range(H)] mod = 10 ** 9 + 7 if a[0][0] != a[-1][-1]: print(0) exit(0) from collections import deque as dq Q = dq([(0, H * W - 1)]) d1 = [1, 0] d2 = [-1, 0] dp = [[0] * (H * W) for _ in range(H * W)] dp[0][-1] = 1 vis = [[0] * (H * W) for _ in range(H * W)] while len(Q): u, v = Q.popleft() if vis[u][v]: continue vis[u][v] = 1 i, j = u // W, u % W y, x = v // W, v % W for k in range(2): i2, j2 = i + d1[k], j + d1[~k] if not (i2 in range(H) and j2 in range(W)): continue u2 = i2 * W + j2 for kk in range(2): y2, x2 = y + d2[kk], x + d2[~kk] if not (y2 in range(H) and x2 in range(W)): continue if a[i2][j2] != a[y2][x2]: continue v2 = y2 * W + x2 dp[u2][v2] += dp[u][v] dp[u2][v2] %= mod Q.append((u2, v2)) #print((i, j), (y,x),(i2, j2),(y2,x2)) #print((i, j), (y, x), len(Q)) res = 0 for i in range(H): for j in range(W): res += dp[i * W + j][i * W + j] res %= mod for i in range(H): for j in range(W): for k in range(2): u, v = i + d1[k], j + d1[~k] if u in range(H) and v in range(W) and a[i][j] == a[u][v]: res += dp[i * W + j][u * W + v] res %= mod print(res)