結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | rlangevin |
提出日時 | 2023-10-10 00:11:48 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,502 bytes |
コンパイル時間 | 529 ms |
コンパイル使用メモリ | 87,080 KB |
実行使用メモリ | 379,332 KB |
最終ジャッジ日時 | 2023-10-10 00:12:14 |
合計ジャッジ時間 | 17,994 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
71,608 KB |
testcase_01 | AC | 82 ms
71,552 KB |
testcase_02 | AC | 107 ms
77,556 KB |
testcase_03 | AC | 78 ms
71,576 KB |
testcase_04 | AC | 79 ms
71,568 KB |
testcase_05 | AC | 83 ms
71,664 KB |
testcase_06 | AC | 85 ms
71,592 KB |
testcase_07 | AC | 84 ms
71,788 KB |
testcase_08 | AC | 84 ms
71,788 KB |
testcase_09 | AC | 81 ms
71,700 KB |
testcase_10 | AC | 79 ms
71,732 KB |
testcase_11 | AC | 82 ms
71,784 KB |
testcase_12 | AC | 110 ms
71,504 KB |
testcase_13 | AC | 109 ms
78,660 KB |
testcase_14 | AC | 101 ms
78,280 KB |
testcase_15 | AC | 300 ms
116,528 KB |
testcase_16 | AC | 283 ms
114,324 KB |
testcase_17 | AC | 553 ms
141,008 KB |
testcase_18 | AC | 1,713 ms
276,476 KB |
testcase_19 | AC | 1,970 ms
276,740 KB |
testcase_20 | AC | 1,556 ms
276,476 KB |
testcase_21 | AC | 1,645 ms
276,580 KB |
testcase_22 | AC | 1,597 ms
276,892 KB |
testcase_23 | AC | 86 ms
73,936 KB |
testcase_24 | AC | 84 ms
73,956 KB |
testcase_25 | AC | 86 ms
74,084 KB |
testcase_26 | AC | 86 ms
73,884 KB |
testcase_27 | AC | 85 ms
74,060 KB |
testcase_28 | TLE | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
M = 205 def encode(a, b, c, d): now = a now *= M now += b now *= M now += c now *= M now += d return now def decode(v): d = v % M v //= M c = v % M v //= M b = v % M v //= M return (v, b, c, d) H, W = map(int, input().split()) S = [] for i in range(H): S.append(list(input())) from collections import * Q = deque() if S[0][0] != S[-1][-1]: print(0) exit() mod = 10**9 + 7 Q.append(encode(0, 0, H - 1, W - 1)) D = defaultdict(int) D[encode(0, 0, H - 1, W - 1)] = 1 dx = [1, 0] dy = [0, 1] ans = 0 SS = set() seen = set() while Q: t = Q.popleft() sx, sy, gx, gy = decode(t) if gx + gy <= sx + sy + 1: if abs(sx - gx) + abs(sy - gy) <= 1 and t not in SS: SS.add(t) ans += D[encode(sx, sy, gx, gy)] ans %= mod continue for a in range(2): for b in range(2): nsx = sx + dx[a] nsy = sy + dy[a] ngx = gx - dx[b] ngy = gy - dy[b] if nsx < 0 or nsx > H - 1 or nsy < 0 or nsy > W - 1: continue if ngx < 0 or ngx > H - 1 or ngy < 0 or ngy > W - 1: continue if S[nsx][nsy] != S[ngx][ngy]: continue nt = encode(nsx, nsy, ngx, ngy) D[nt] += D[t] D[nt] %= mod if nt in seen: continue seen.add(nt) Q.append(nt) print(ans)