結果
問題 | No.460 裏表ちわーわ |
ユーザー | yuppe19 😺 |
提出日時 | 2016-12-11 10:36:47 |
言語 | Python2 (2.7.18) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,200 bytes |
コンパイル時間 | 539 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-29 03:28:03 |
合計ジャッジ時間 | 1,670 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
6,820 KB |
testcase_01 | AC | 10 ms
6,816 KB |
testcase_02 | AC | 11 ms
6,820 KB |
testcase_03 | AC | 10 ms
6,820 KB |
testcase_04 | AC | 10 ms
6,816 KB |
testcase_05 | AC | 16 ms
6,816 KB |
testcase_06 | AC | 15 ms
6,820 KB |
testcase_07 | AC | 14 ms
6,820 KB |
testcase_08 | AC | 15 ms
6,816 KB |
testcase_09 | AC | 10 ms
6,820 KB |
testcase_10 | AC | 15 ms
6,820 KB |
testcase_11 | AC | 15 ms
6,820 KB |
testcase_12 | AC | 15 ms
6,816 KB |
testcase_13 | WA | - |
testcase_14 | AC | 15 ms
6,820 KB |
testcase_15 | WA | - |
testcase_16 | AC | 15 ms
6,816 KB |
testcase_17 | AC | 15 ms
6,816 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 15 ms
6,816 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 14 ms
6,816 KB |
testcase_25 | AC | 9 ms
6,816 KB |
testcase_26 | AC | 10 ms
6,820 KB |
testcase_27 | WA | - |
ソースコード
#!/usr/bin/python2 # -*- coding: utf-8 -*- # † from itertools import chain flatten = chain.from_iterable R, C = map(int, raw_input().split()) board_width = C board_height = R n = board_width * board_height # Set up the matrix of button pushes A = [[0]*n for i in xrange(n)] for i in xrange(board_width): for j in xrange(board_height): idx = i + j * board_width A[idx][idx] = 1 if i > 0: A[idx - 1][idx] = 1 if i < board_width - 1: A[idx + 1][idx] = 1 if j > 0: A[idx - board_width][idx] = 1 if j < board_height - 1: A[idx + board_width][idx] = 1 # if i > 0 and j > 0: A[idx - board_width - 1][idx] = 1 if i > 0 and j < board_height - 1: A[idx + board_width - 1][idx] = 1 if i < board_width - 1 and j > 0: A[idx - board_width + 1][idx] = 1 if i < board_width - 1 and j < board_height - 1: A[idx + board_width + 1][idx] = 1 # A couple helpers 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] # The input state to solve #state = map(int, '1011100111110001100111010') mat = [map(int, raw_input().split()) for _ in xrange(R)] state = list(flatten(mat)) G = state[:] #print state # Solve via something like Gaussian Elimination for col in xrange(n): # find the first row with a 1 in this column for row in xrange(col,n): if A[row][col] == 1: swap_rows(A, row, col) swap_rows(state, row, col) for other in xrange(n): if other != col and A[other][col] == 1: A[other] = add_rows(A, other, col) state[other] = state[other] ^ state[col] # Print out the buttons to be pressed #for j in xrange(board_height): # print ''.join(map(str,state[j*board_width:(j+1)*board_width])) 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