結果

問題 No.3803 Crossword Key Checker
ユーザー Skyシャーレ
提出日時 2026-10-07 13:39:48
言語 Python3
(3.15.2 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 1,713 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 241 ms
コンパイル使用メモリ 14,848 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2026-11-14 14:32:16
合計ジャッジ時間 3,524 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

def main():
    t = sys.stdin.read().split()
    H, W = int(t[0]), int(t[1])
    grid = t[2:2 + H]
    K = int(t[2 + H])
    R = t[3 + H:3 + H + K]
    C = t[3 + H + K:3 + H + 2 * K]

    def white(i, j):
        return 0 <= i < H and 0 <= j < W and grid[i][j] == '.'

    letters = {}  # マス -> 書き込まれた文字

    def place(i, j, di, dj, s, exists):
        # カギがないのに答えがある、またはカギがあるのに '-' なら不成立
        if not exists:
            return s == '-'
        if s == '-':
            return False
        # 連続する白マスの数を数える
        n = 0
        while white(i + di * n, j + dj * n):
            n += 1
        if n != len(s):
            return False
        # 重なるマスの文字が一致するか確認しながら書き込む
        for k, ch in enumerate(s):
            cell = (i + di * k, j + dj * k)
            if letters.setdefault(cell, ch) != ch:
                return False
        return True

    idx = 0
    for i in range(H):
        for j in range(W):
            if not white(i, j):
                continue
            a = not white(i, j - 1) and white(i, j + 1)  # 横のカギ
            d = not white(i - 1, j) and white(i + 1, j)  # 縦のカギ
            if not (a or d):
                continue
            if idx >= K:  # カギの数が K を超えている
                print("No")
                return
            # 横・縦どちらも同じ添字 idx を使う
            if not place(i, j, 0, 1, R[idx], a) or not place(i, j, 1, 0, C[idx], d):
                print("No")
                return
            idx += 1

    print("Yes" if idx == K else "No")

main()
0