結果

問題 No.1916 Making Palindrome on Gird
ユーザー lilictakalilictaka
提出日時 2022-05-16 18:30:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,952 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 141,980 KB
最終ジャッジ日時 2023-10-12 12:15:03
合計ジャッジ時間 24,417 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,380 KB
testcase_01 AC 71 ms
71,264 KB
testcase_02 AC 110 ms
77,336 KB
testcase_03 WA -
testcase_04 AC 111 ms
77,728 KB
testcase_05 AC 108 ms
77,488 KB
testcase_06 AC 117 ms
77,580 KB
testcase_07 AC 111 ms
77,584 KB
testcase_08 AC 112 ms
77,564 KB
testcase_09 AC 72 ms
71,124 KB
testcase_10 AC 71 ms
71,376 KB
testcase_11 AC 110 ms
77,376 KB
testcase_12 WA -
testcase_13 AC 433 ms
97,756 KB
testcase_14 AC 400 ms
93,548 KB
testcase_15 WA -
testcase_16 AC 347 ms
90,500 KB
testcase_17 AC 1,135 ms
131,768 KB
testcase_18 AC 1,288 ms
141,704 KB
testcase_19 AC 1,220 ms
141,716 KB
testcase_20 AC 1,219 ms
141,668 KB
testcase_21 AC 1,203 ms
141,592 KB
testcase_22 AC 1,159 ms
141,744 KB
testcase_23 AC 1,142 ms
140,584 KB
testcase_24 AC 1,124 ms
140,884 KB
testcase_25 AC 1,112 ms
140,364 KB
testcase_26 AC 1,133 ms
141,708 KB
testcase_27 AC 1,139 ms
140,448 KB
testcase_28 AC 1,228 ms
141,904 KB
testcase_29 AC 1,232 ms
141,932 KB
testcase_30 AC 1,230 ms
141,980 KB
testcase_31 AC 1,224 ms
141,972 KB
testcase_32 AC 1,227 ms
141,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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())
0