結果

問題 No.323 yuki国
ユーザー rpy3cpprpy3cpp
提出日時 2015-12-16 23:13:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,143 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-14 11:09:16
合計ジャッジ時間 2,002 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,132 KB
testcase_01 AC 15 ms
8,520 KB
testcase_02 AC 15 ms
8,452 KB
testcase_03 AC 15 ms
8,372 KB
testcase_04 WA -
testcase_05 AC 15 ms
8,404 KB
testcase_06 AC 15 ms
8,544 KB
testcase_07 WA -
testcase_08 AC 15 ms
8,460 KB
testcase_09 WA -
testcase_10 AC 15 ms
8,364 KB
testcase_11 AC 16 ms
8,504 KB
testcase_12 AC 16 ms
8,128 KB
testcase_13 AC 22 ms
8,592 KB
testcase_14 AC 17 ms
8,496 KB
testcase_15 AC 23 ms
8,620 KB
testcase_16 AC 25 ms
8,704 KB
testcase_17 WA -
testcase_18 AC 17 ms
8,476 KB
testcase_19 AC 16 ms
8,552 KB
testcase_20 AC 16 ms
8,448 KB
testcase_21 AC 16 ms
8,424 KB
testcase_22 AC 21 ms
8,488 KB
testcase_23 AC 16 ms
8,524 KB
testcase_24 WA -
testcase_25 AC 16 ms
8,492 KB
testcase_26 AC 26 ms
8,604 KB
testcase_27 AC 16 ms
8,276 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 15 ms
8,448 KB
testcase_31 AC 15 ms
8,452 KB
testcase_32 AC 16 ms
8,476 KB
testcase_33 AC 16 ms
8,520 KB
testcase_34 AC 15 ms
8,400 KB
testcase_35 AC 16 ms
8,120 KB
testcase_36 AC 15 ms
8,488 KB
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    H, W = map(int, input().split())
    A, Si, Sj = map(int, input().split())
    B, Gi, Gj = map(int, input().split())
    Ms = [[c == '*' for c in input()] for i in range(H)]
    return H, W, A, Si, Sj, B, Gi, Gj, Ms


def solve(H, W, A, Si, Sj, B, Gi, Gj, Ms):
    if (A - B + (Si - Gi) + (Sj - Gj)) % 2:
        return False
    lower = [[float('inf')] * W for h in range(H)]
    upper = [[-1] * W for h in range(H)]
    lower[Si][Sj] = A
    upper[Si][Sj] = A
    fs = set([(Si, Sj)])
    while fs:
        nfs = set()
        for i, j in fs:
            m = Ms[i][j]
            min_snow = lower[i][j]
            max_snow = upper[i][j]
            for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                ni = i + di
                nj = j + dj
                if ni < 0 or ni >= H or nj < 0 or nj >= W:
                    continue
                if update_status(m, min_snow, max_snow, ni, nj, upper, lower, Ms):
                    nfs.add((ni, nj))
        if lower[Gi][Gj] <= B and upper[Gi][Gj] >= B:
            return True
        fs = nfs
    return False


def update_status(m, min_snow, max_snow, ni, nj, upper, lower, Ms):
    n_m = Ms[ni][nj]
    if m != n_m:
        n_min_snow = min_snow + 2 * n_m - 1
        if n_min_snow == 0:
            n_min_snow = float('inf')
        n_max_snow = max_snow + 2 * n_m - 1
        if n_max_snow == 0:
            n_max_snow = -1
    elif n_m:
        n_min_snow = min_snow + 1
        n_max_snow = float('inf')
    else:
        if min_snow == 1:
            n_min_snow = float('inf')
        elif min_snow % 2:
            n_min_snow = 2
        else:
            n_min_snow = 1
        n_max_snow = min_snow - 1        
        if n_max_snow == 0:
            n_max_snow = -1
    changed = False        
    if n_min_snow < lower[ni][nj]:
        lower[ni][nj] = n_min_snow
        changed = True
    if n_max_snow > upper[ni][nj]:
        upper[ni][nj] = n_max_snow
        changed = True
    return changed
                

H, W, A, Si, Sj, B, Gi, Gj, Ms = read_data()
if solve(H, W, A, Si, Sj, B, Gi, Gj, Ms):
    print('Yes')
else:
    print('No')
0