結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | mkawa2 |
提出日時 | 2022-04-29 22:47:00 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,834 bytes |
コンパイル時間 | 285 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 269,308 KB |
最終ジャッジ日時 | 2024-06-29 04:24:18 |
合計ジャッジ時間 | 16,481 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
59,264 KB |
testcase_01 | AC | 44 ms
53,760 KB |
testcase_02 | AC | 74 ms
74,456 KB |
testcase_03 | AC | 42 ms
54,144 KB |
testcase_04 | AC | 44 ms
58,880 KB |
testcase_05 | AC | 42 ms
54,272 KB |
testcase_06 | AC | 46 ms
59,136 KB |
testcase_07 | AC | 46 ms
59,776 KB |
testcase_08 | AC | 45 ms
59,776 KB |
testcase_09 | AC | 46 ms
59,520 KB |
testcase_10 | AC | 42 ms
54,016 KB |
testcase_11 | AC | 45 ms
59,648 KB |
testcase_12 | AC | 46 ms
59,520 KB |
testcase_13 | AC | 80 ms
77,044 KB |
testcase_14 | AC | 77 ms
76,672 KB |
testcase_15 | AC | 308 ms
85,120 KB |
testcase_16 | AC | 202 ms
79,360 KB |
testcase_17 | AC | 593 ms
105,748 KB |
testcase_18 | AC | 1,596 ms
194,304 KB |
testcase_19 | AC | 1,561 ms
190,660 KB |
testcase_20 | AC | 1,583 ms
193,716 KB |
testcase_21 | AC | 1,591 ms
194,820 KB |
testcase_22 | AC | 1,558 ms
191,344 KB |
testcase_23 | AC | 43 ms
54,272 KB |
testcase_24 | AC | 42 ms
54,656 KB |
testcase_25 | AC | 41 ms
54,400 KB |
testcase_26 | AC | 42 ms
54,272 KB |
testcase_27 | AC | 41 ms
54,400 KB |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
ソースコード
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() n = h+w-1 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) mid = (n-1)//2 if n & 1: for i in range(h): j = mid-i if not 0 <= j < w: continue dp[i, j, i, j] = 1 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]: dp[i, j, u, v] = 1 for _ in range(mid): 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) print(dp[0, 0, h-1, w-1])