結果

問題 No.460 裏表ちわーわ
ユーザー yuppe19 😺yuppe19 😺
提出日時 2016-12-11 22:08:25
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,536 bytes
コンパイル時間 49 ms
コンパイル使用メモリ 6,712 KB
実行使用メモリ 6,336 KB
最終ジャッジ日時 2023-08-19 11:37:00
合計ジャッジ時間 1,736 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,092 KB
testcase_01 AC 13 ms
6,200 KB
testcase_02 AC 14 ms
6,264 KB
testcase_03 AC 12 ms
6,208 KB
testcase_04 AC 12 ms
6,040 KB
testcase_05 AC 18 ms
6,084 KB
testcase_06 AC 17 ms
6,176 KB
testcase_07 AC 18 ms
6,148 KB
testcase_08 AC 18 ms
6,044 KB
testcase_09 AC 13 ms
6,048 KB
testcase_10 AC 18 ms
6,172 KB
testcase_11 AC 18 ms
6,076 KB
testcase_12 AC 18 ms
6,084 KB
testcase_13 WA -
testcase_14 AC 18 ms
6,268 KB
testcase_15 WA -
testcase_16 AC 18 ms
6,116 KB
testcase_17 AC 18 ms
6,152 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 18 ms
6,048 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 18 ms
6,148 KB
testcase_25 AC 12 ms
6,152 KB
testcase_26 AC 12 ms
6,164 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
from itertools import product
from itertools import chain
from copy import deepcopy
flatten = chain.from_iterable

R, C = map(int, raw_input().split())
n = R * C

A = [[0 for j in range(n)] for i in range(n)] # A[n][n]

for r in xrange(R):
    for c in xrange(C):
        i = r * C + c
        for dr, dc in product([-1, 0, 1], repeat=2):
            nr = r + dr
            nc = c + dc
            if not (0 <= nr < R and 0 <= nc < C):
                continue
            ni = nr * C + nc
            A[i][ni] = 1

def add_rows(A, i, j):
    return [(A[i][k] + A[j][k]) % 2 for k in xrange(n)]

def swap_rows(A, i, j):
    A[i], A[j] = A[j], A[i]

mat = [map(int, raw_input().split()) for _ in xrange(R)]
state = list(flatten(mat))
G = deepcopy(state)

for c in xrange(n):
    for r in xrange(c, n):
        if A[r][c] == 1:
            swap_rows(A, r, c)
            swap_rows(state, r, c)
            for other in xrange(n):
                if other != c and A[other][c] == 1:
                    A[other] = add_rows(A, other, c)
                    state[other] ^= state[c]

for i in xrange(R*C):
    if state[i]:
        r, c = divmod(i, C)
        for dr in [-1, 0, 1]:
            for dc in [-1, 0, 1]:
                nr = r + dr
                nc = c + dc
                if not (0 <= nr < R and 0 <= nc < C):
                    continue
                G[nr*C+nc] = 1 - G[nr*C+nc]

if any(x!=0 for x in G):
    print 'Impossible'
    exit(0)

res = state.count(1)
print res
0