結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | mkawa2 |
提出日時 | 2022-04-29 22:24:03 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,905 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,516 KB |
実行使用メモリ | 270,860 KB |
最終ジャッジ日時 | 2024-06-29 03:59:45 |
合計ジャッジ時間 | 20,763 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
61,744 KB |
testcase_01 | AC | 42 ms
54,944 KB |
testcase_02 | AC | 76 ms
76,516 KB |
testcase_03 | AC | 42 ms
54,820 KB |
testcase_04 | AC | 46 ms
60,808 KB |
testcase_05 | AC | 47 ms
60,996 KB |
testcase_06 | AC | 48 ms
60,380 KB |
testcase_07 | AC | 47 ms
60,512 KB |
testcase_08 | AC | 48 ms
60,240 KB |
testcase_09 | AC | 47 ms
60,148 KB |
testcase_10 | AC | 42 ms
55,124 KB |
testcase_11 | AC | 47 ms
61,396 KB |
testcase_12 | AC | 47 ms
60,512 KB |
testcase_13 | AC | 77 ms
76,576 KB |
testcase_14 | AC | 69 ms
74,348 KB |
testcase_15 | AC | 387 ms
93,832 KB |
testcase_16 | AC | 312 ms
86,804 KB |
testcase_17 | AC | 722 ms
127,620 KB |
testcase_18 | AC | 2,619 ms
265,720 KB |
testcase_19 | AC | 2,552 ms
264,052 KB |
testcase_20 | AC | 2,571 ms
266,328 KB |
testcase_21 | AC | 2,629 ms
265,336 KB |
testcase_22 | AC | 2,582 ms
264,204 KB |
testcase_23 | AC | 42 ms
54,776 KB |
testcase_24 | AC | 43 ms
56,172 KB |
testcase_25 | AC | 43 ms
55,696 KB |
testcase_26 | AC | 42 ms
55,672 KB |
testcase_27 | AC | 42 ms
55,336 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)