結果

問題 No.1916 Making Palindrome on Gird
ユーザー AEnAEn
提出日時 2022-05-26 13:33:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 81,884 KB
実行使用メモリ 73,176 KB
最終ジャッジ日時 2023-10-20 19:25:10
合計ジャッジ時間 4,034 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
testcase_10 AC 37 ms
53,460 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 58 ms
68,320 KB
testcase_24 AC 59 ms
68,316 KB
testcase_25 AC 59 ms
68,312 KB
testcase_26 AC 59 ms
68,312 KB
testcase_27 AC 61 ms
68,320 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
m = []
for i in range(H):
    s = list(input())
    m.append(s)

mod = 10**9+7
for i in range((H+W-1)//2):
    u, d = set(), set()
    sm = i
    for j in range(i+1):
        p, q = sm-j, j
        u.add(m[p][q])
        d.add(m[H-1-p][W-1-q])
    g = u.intersection(d)
    for j in range(i+1):
        p, q = sm-j, j
        if m[p][q] not in g:
            m[p][q] = '#'
        if m[H-1-p][W-1-q] not in g:
            m[H-1-p][W-1-q] = '#'

cnt = [[0]*W for _ in range(H)]
cnt[0][0] = 1
for i in range(H):
    for j in range(W):
        if i == j == 0:
            continue
        if m[i][j] == '#':
            break
        else:
            if i == 0 and m[i][j-1] != '#':
                cnt[i][j] += cnt[i][j-1]
            elif j == 0 and m[i-1][j] != '#':
                cnt[i][j] += cnt[i-1][j]
            else:
                if m[i-1][j] != '#':
                    cnt[i][j] += cnt[i-1][j]
                if m[i][j-1] != '#':
                    cnt[i][j] += cnt[i][j-1]
            cnt[i][j] %= mod

print(cnt[-1][-1])
0