結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | mkawa2 |
提出日時 | 2022-04-29 22:24:03 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,905 bytes |
コンパイル時間 | 289 ms |
コンパイル使用メモリ | 87,168 KB |
実行使用メモリ | 269,184 KB |
最終ジャッジ日時 | 2023-09-11 13:45:26 |
合計ジャッジ時間 | 22,436 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 88 ms
71,908 KB |
testcase_01 | AC | 91 ms
71,564 KB |
testcase_02 | AC | 116 ms
77,860 KB |
testcase_03 | AC | 86 ms
71,816 KB |
testcase_04 | AC | 93 ms
76,376 KB |
testcase_05 | AC | 91 ms
76,228 KB |
testcase_06 | AC | 91 ms
76,340 KB |
testcase_07 | AC | 94 ms
76,028 KB |
testcase_08 | AC | 93 ms
76,228 KB |
testcase_09 | AC | 92 ms
76,016 KB |
testcase_10 | AC | 89 ms
71,492 KB |
testcase_11 | AC | 94 ms
76,352 KB |
testcase_12 | AC | 92 ms
76,272 KB |
testcase_13 | AC | 116 ms
77,920 KB |
testcase_14 | AC | 115 ms
78,288 KB |
testcase_15 | AC | 417 ms
94,424 KB |
testcase_16 | AC | 350 ms
88,120 KB |
testcase_17 | AC | 786 ms
128,820 KB |
testcase_18 | AC | 2,585 ms
265,520 KB |
testcase_19 | AC | 2,602 ms
265,672 KB |
testcase_20 | AC | 2,579 ms
266,216 KB |
testcase_21 | AC | 2,581 ms
265,628 KB |
testcase_22 | AC | 2,580 ms
264,464 KB |
testcase_23 | AC | 89 ms
71,636 KB |
testcase_24 | AC | 87 ms
71,596 KB |
testcase_25 | AC | 89 ms
71,596 KB |
testcase_26 | AC | 89 ms
71,656 KB |
testcase_27 | AC | 90 ms
71,632 KB |
testcase_28 | TLE | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 from collections import defaultdict h, w = LI() ss = [SI() for _ in range(h)] if ss[0][0] != ss[h-1][w-1]: print(0) exit() dij = [(0, 1, 0, -1), (1, 0, 0, -1), (0, 1, -1, 0), (1, 0, -1, 0)] dp = defaultdict(int) dp[0, 0, h-1, w-1] = 1 n = h+w-1 for _ in range((n-1)//2): ndp = defaultdict(int) for (i, j, u, v), pre in dp.items(): for di, dj, du, dv in dij: ni, nj, nu, nv = i+di, j+dj, u+du, v+dv if not 0 <= ni < h: continue if not 0 <= nj < w: continue if not 0 <= nu < h: continue if not 0 <= nv < w: continue if ss[ni][nj] != ss[nu][nv]: continue ndp[ni, nj, nu, nv] += pre ndp[ni, nj, nu, nv] %= md dp = ndp # pDB(dp) ans = 0 mid = (n-1)//2 if n & 1: for i in range(h): j = mid-i if not 0 <= j < w: continue ans += dp[i, j, i, j] ans %= md else: for i in range(h): j = mid-i if not 0 <= j < w: continue for u, v in [(i+1, j), (i, j+1)]: if 0 <= u < h and 0 <= v < w and ss[i][j] == ss[u][v]: ans += dp[i, j, u, v] ans %= md print(ans)