結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | lilictaka |
提出日時 | 2022-05-16 18:34:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,310 ms / 3,000 ms |
コード長 | 2,037 bytes |
コンパイル時間 | 432 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 140,800 KB |
最終ジャッジ日時 | 2024-09-14 11:14:09 |
合計ジャッジ時間 | 23,538 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,480 KB |
testcase_01 | AC | 41 ms
52,480 KB |
testcase_02 | AC | 94 ms
76,424 KB |
testcase_03 | AC | 42 ms
53,248 KB |
testcase_04 | AC | 96 ms
76,416 KB |
testcase_05 | AC | 90 ms
75,904 KB |
testcase_06 | AC | 99 ms
76,160 KB |
testcase_07 | AC | 95 ms
76,416 KB |
testcase_08 | AC | 97 ms
75,904 KB |
testcase_09 | AC | 42 ms
53,120 KB |
testcase_10 | AC | 41 ms
52,608 KB |
testcase_11 | AC | 97 ms
76,160 KB |
testcase_12 | AC | 78 ms
71,680 KB |
testcase_13 | AC | 513 ms
96,896 KB |
testcase_14 | AC | 398 ms
92,288 KB |
testcase_15 | AC | 652 ms
104,192 KB |
testcase_16 | AC | 344 ms
89,344 KB |
testcase_17 | AC | 1,150 ms
130,304 KB |
testcase_18 | AC | 1,310 ms
140,672 KB |
testcase_19 | AC | 1,252 ms
140,160 KB |
testcase_20 | AC | 1,254 ms
140,544 KB |
testcase_21 | AC | 1,250 ms
140,160 KB |
testcase_22 | AC | 1,203 ms
140,544 KB |
testcase_23 | AC | 1,158 ms
139,520 KB |
testcase_24 | AC | 1,144 ms
139,520 KB |
testcase_25 | AC | 1,134 ms
139,392 KB |
testcase_26 | AC | 1,148 ms
140,288 KB |
testcase_27 | AC | 1,086 ms
139,392 KB |
testcase_28 | AC | 1,244 ms
140,672 KB |
testcase_29 | AC | 1,244 ms
140,672 KB |
testcase_30 | AC | 1,244 ms
140,544 KB |
testcase_31 | AC | 1,245 ms
140,672 KB |
testcase_32 | AC | 1,245 ms
140,800 KB |
ソースコード
H,W = map(int,input().split()) board = [] for _ in range(H): tmp = list(input()) board.append(tmp) def convert(k,h1,h2): return (H**2) * k + H * h1 + h2 def ch1(k,h,mid): return (h,mid-k-h) def ch2(k,h,mid): return (h,mid+k-h) mod = 10 ** 9 + 7 def isin(h,w): if 0 <= h < H and 0 <= w < W: return True else: return False def check(k,h1,h2,mid1,mid2): h1,w1 = ch1(k,h1,mid1) h2,w2 = ch2(k,h2,mid2) if isin(h1,w1) and isin(h2,w2) and board[h1][w1] == board[h2][w2]: return True else: return False def solve(): if (H + W ) % 2 == 0: mid = (H-1+W-1) //2 dp = [0 for _ in range((H**2) * (mid+1))] for h1 in range(H): dp[convert(0,h1,h1)] = 1 for k in range(mid): for h1 in range(H): for h2 in range(H): for dh1,dh2 in [(-1,0),(-1,1),(0,0),(0,1)]: nh1 = h1 + dh1 nh2 = h2 + dh2 if check(k+1,nh1,nh2,mid,mid): dp[convert(k+1,nh1,nh2)] += dp[convert(k,h1,h2)] dp[convert(k+1,nh1,nh2)] %= mod return dp[convert(mid,0,H-1)] else: mid1 = (H-1+W-1 -1) //2 mid2 = (H-1+W-1 +1) //2 dp = [0 for _ in range((H**2) * (mid1+1))] for h1 in range(H): if check(0,h1,h1,mid1,mid2): dp[convert(0,h1,h1)] += 1 if check(0,h1,h1+1,mid1,mid2): dp[convert(0,h1,h1+1)] += 1 for k in range(mid1): for h1 in range(H): for h2 in range(H): for dh1,dh2 in [(-1,0),(-1,1),(0,0),(0,1)]: nh1 = h1 + dh1 nh2 = h2 + dh2 if check(k+1,nh1,nh2,mid1,mid2): dp[convert(k+1,nh1,nh2)] += dp[convert(k,h1,h2)] dp[convert(k+1,nh1,nh2)] %= mod return dp[(convert(mid1,0,H-1))] print(solve())