結果

問題 No.359 門松行列
ユーザー maspymaspy
提出日時 2020-03-28 17:15:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,128 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 8,236 KB
最終ジャッジ日時 2023-08-30 18:01:43
合計ジャッジ時間 1,355 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,052 KB
testcase_01 AC 17 ms
8,016 KB
testcase_02 AC 17 ms
8,012 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


T = int(readline())


def test(A):
    if any(x == 0 for x in A):
        return False

    def is_kadomatsu(a, b, c):
        if a == c:
            return False
        return (a < b > c) or (a > b < c)
    return all(is_kadomatsu(A[i], A[j], A[k]) for i, j, k in ((0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)))


def solve():
    L = int(readline())
    A = [0] * 9
    for i in range(3):
        A[3 * i: 3 * i + 3] = map(int, readline().split())
    i, j = (i for i, x in enumerate(A) if not x)
    nums = [L, L + 1]
    for x in A:
        nums.append(x - 1)
        nums.append(x)
        nums.append(x + 1)
        nums.append(L - x + 1)
        nums.append(L - x)
        nums.append(L - x - 1)
    nums = sorted(set(x for x in nums if 1 <= x <= L))
    ret = 0
    for n, m in zip(nums, nums[1:]):
        A[i] = n
        A[j] = L - n
        if test(A):
            ret += m - n
    return ret


for _ in range(T):
    print(solve())
0