結果

問題 No.1566 All Even
ユーザー mkawa2mkawa2
提出日時 2021-06-28 10:42:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,863 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 11,184 KB
実行使用メモリ 8,560 KB
最終ジャッジ日時 2023-09-07 18:18:13
合計ジャッジ時間 2,021 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,076 KB
testcase_01 AC 18 ms
8,408 KB
testcase_02 AC 107 ms
8,240 KB
testcase_03 AC 16 ms
8,504 KB
testcase_04 AC 16 ms
8,192 KB
testcase_05 AC 17 ms
8,384 KB
testcase_06 AC 17 ms
8,556 KB
testcase_07 AC 17 ms
8,556 KB
testcase_08 AC 20 ms
8,240 KB
testcase_09 AC 16 ms
8,448 KB
testcase_10 AC 34 ms
8,052 KB
testcase_11 AC 16 ms
8,512 KB
testcase_12 AC 16 ms
8,412 KB
testcase_13 AC 17 ms
8,560 KB
testcase_14 AC 16 ms
8,508 KB
testcase_15 AC 16 ms
8,416 KB
testcase_16 AC 16 ms
8,380 KB
testcase_17 AC 19 ms
8,028 KB
testcase_18 AC 17 ms
8,072 KB
testcase_19 AC 17 ms
8,248 KB
testcase_20 AC 17 ms
8,052 KB
testcase_21 AC 17 ms
8,180 KB
testcase_22 AC 106 ms
8,100 KB
testcase_23 AC 17 ms
8,232 KB
testcase_24 AC 17 ms
8,392 KB
testcase_25 AC 17 ms
8,024 KB
testcase_26 AC 16 ms
8,452 KB
testcase_27 AC 106 ms
8,108 KB
testcase_28 AC 17 ms
8,376 KB
testcase_29 AC 16 ms
8,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7

n,m=LI()
xyz=LLI(m)

if n>=7:
    for x,y,z in xyz:
        if z==0:
            print(0)
            exit()
    print(1)
    exit()

xyz=[(x-1,y-1,z) for x,y,z in xyz]
ans=0
for bit in range(1 << 2*n-1):
    tt = [[0]*n for _ in range(n)]
    for i in range(n):
        tt[i][0] = bit >> i & 1
    for j in range(1, n):
        tt[0][j] = bit >> j+n-1 & 1
    for i in range(1, n):
        for j in range(1, n):
            s = tt[i-1][j-1] ^ tt[i][j-1] ^ tt[i-1][j]
            tt[i][j] = s

    cs = [[0]*(n+1) for _ in range(n+1)]
    for i in range(n):
        for j in range(n):
            cs[i+1][j+1] = cs[i+1][j] ^ tt[i][j]
    for j in range(n):
        for i in range(n):
            cs[i+1][j+1] ^= cs[i][j+1]

    def ok():
        for x,y,z in xyz:
            if tt[x][y]==z:return False
        for d in range(3, n+1):
            for i in range(n-d+1):
                for j in range(n-d+1):
                    x = cs[i][j] ^ cs[i+d][j+d] ^ cs[i+d][j] ^ cs[i][j+d]
                    if x: return False
        return True

    # print("OK" if ok() else "NG")
    if ok():
        ans+=1
        # p2D(tt)
        # print()

print(ans)
0