結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | lilictaka |
提出日時 | 2022-05-16 18:30:38 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,952 bytes |
コンパイル時間 | 474 ms |
コンパイル使用メモリ | 82,064 KB |
実行使用メモリ | 140,768 KB |
最終ジャッジ日時 | 2024-09-14 11:10:06 |
合計ジャッジ時間 | 23,784 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
52,480 KB |
testcase_01 | AC | 42 ms
52,864 KB |
testcase_02 | AC | 84 ms
76,240 KB |
testcase_03 | WA | - |
testcase_04 | AC | 84 ms
76,032 KB |
testcase_05 | AC | 83 ms
76,160 KB |
testcase_06 | AC | 89 ms
76,128 KB |
testcase_07 | AC | 86 ms
76,032 KB |
testcase_08 | AC | 86 ms
75,904 KB |
testcase_09 | AC | 42 ms
53,120 KB |
testcase_10 | AC | 41 ms
52,096 KB |
testcase_11 | AC | 86 ms
76,056 KB |
testcase_12 | WA | - |
testcase_13 | AC | 409 ms
96,768 KB |
testcase_14 | AC | 378 ms
91,980 KB |
testcase_15 | WA | - |
testcase_16 | AC | 323 ms
89,216 KB |
testcase_17 | AC | 1,111 ms
130,204 KB |
testcase_18 | AC | 1,276 ms
140,492 KB |
testcase_19 | AC | 1,220 ms
140,288 KB |
testcase_20 | AC | 1,225 ms
140,396 KB |
testcase_21 | AC | 1,223 ms
140,288 KB |
testcase_22 | AC | 1,156 ms
140,768 KB |
testcase_23 | AC | 1,125 ms
139,272 KB |
testcase_24 | AC | 1,110 ms
139,380 KB |
testcase_25 | AC | 1,116 ms
139,248 KB |
testcase_26 | AC | 1,125 ms
140,264 KB |
testcase_27 | AC | 1,137 ms
139,380 KB |
testcase_28 | AC | 1,210 ms
140,416 KB |
testcase_29 | AC | 1,206 ms
140,416 KB |
testcase_30 | AC | 1,211 ms
140,720 KB |
testcase_31 | AC | 1,217 ms
140,584 KB |
testcase_32 | AC | 1,211 ms
140,288 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): for h2 in range(max(h1-1,0),h1+1): dp[convert(0,h1,h2)] = 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())