結果
| 問題 |
No.359 門松行列
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-28 17:15:55 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,128 bytes |
| コンパイル時間 | 253 ms |
| コンパイル使用メモリ | 12,288 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2025-01-02 11:51:41 |
| 合計ジャッジ時間 | 1,477 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 14 |
ソースコード
#!/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())
maspy