結果

問題 No.5002 stick xor
ユーザー tookunn_1213tookunn_1213
提出日時 2018-05-26 16:21:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 913 ms / 1,000 ms
コード長 2,142 bytes
コンパイル時間 29,219 ms
実行使用メモリ 8,392 KB
スコア 33,243
最終ジャッジ日時 2018-05-26 16:22:02
ジャッジサーバーID
(参考情報)
judge6 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 913 ms
8,388 KB
testcase_01 AC 895 ms
8,388 KB
testcase_02 AC 859 ms
8,384 KB
testcase_03 AC 865 ms
8,300 KB
testcase_04 AC 865 ms
8,292 KB
testcase_05 AC 837 ms
8,380 KB
testcase_06 AC 841 ms
8,388 KB
testcase_07 AC 846 ms
8,296 KB
testcase_08 AC 828 ms
8,384 KB
testcase_09 AC 810 ms
8,388 KB
testcase_10 AC 831 ms
8,380 KB
testcase_11 AC 820 ms
8,300 KB
testcase_12 AC 815 ms
8,384 KB
testcase_13 AC 803 ms
8,388 KB
testcase_14 AC 817 ms
8,392 KB
testcase_15 AC 820 ms
8,296 KB
testcase_16 AC 840 ms
8,296 KB
testcase_17 AC 826 ms
8,388 KB
testcase_18 AC 862 ms
8,384 KB
testcase_19 AC 830 ms
8,392 KB
testcase_20 AC 826 ms
8,384 KB
testcase_21 AC 829 ms
8,388 KB
testcase_22 AC 847 ms
8,300 KB
testcase_23 AC 860 ms
8,380 KB
testcase_24 AC 896 ms
8,384 KB
testcase_25 AC 852 ms
8,384 KB
testcase_26 AC 860 ms
8,392 KB
testcase_27 AC 847 ms
8,380 KB
testcase_28 AC 852 ms
8,300 KB
testcase_29 AC 834 ms
8,384 KB
testcase_30 AC 827 ms
8,388 KB
testcase_31 AC 836 ms
8,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# import time
import random
from heapq import heappush,heappop

def evalute(grid):
    return sum([r.count(0) for r in grid])
def operation_grid(op, grid):
    rev_grid = grid
    if op[1] == op[3]:
        length = op[2] - op[0] + 1
        for i in range(length):
            rev_grid[op[0]-1+i][op[1]-1] = (grid[op[0]-1+i][op[1]-1]+1)&1
    if op[0] == op[2]:
        length = op[3] - op[1] + 1
        for i in range(length):
            rev_grid[op[0]-1][op[1]-1+i] = (grid[op[0]-1][op[1]-1+i]+1)&1
    return rev_grid

def count_black_horizon(grid, base_x, base_y, length):
    return grid[base_y][base_x:base_x + length].count(1)
def count_black_vertical(grid, base_x, base_y, length):
    return [grid[i][base_x] for i in range(base_y,base_y + length)].count(1)

# begin = time.time()
N,K = map(int,input().split())
L = list(map(int,input().split()))
A = [list(map(int,list(input()))) for i in range(N)]

operation = []
P = 3
for k in range(K):
    hq = []
    for x in range(N-L[k]):
        for i in range(P):
            y = random.randint(0, N-L[k])
            horizon_cnt = count_black_horizon(A, x, y, L[k])
            vertical_cnt = count_black_vertical(A, x, y, L[k])
            if horizon_cnt < vertical_cnt:
                heappush(hq, (-vertical_cnt, [y+1, x+1, y+L[k], x+1]))
            else:
                heappush(hq, (-horizon_cnt, [y+1, x+1, y+1, x+L[k]]))
    for y in range(N-L[k]):
        for i in range(P):
            x = random.randint(0, N-L[k])
            horizon_cnt = count_black_horizon(A, x, y, L[k])
            vertical_cnt = count_black_vertical(A, x, y, L[k])
            if horizon_cnt < vertical_cnt:
                heappush(hq, (-vertical_cnt, [y+1, x+1, y+L[k], x+1]))
            else:
                heappush(hq, (-horizon_cnt, [y+1, x+1, y+1, x+L[k]]))
    cnt, op = heappop(hq)
    A = operation_grid(op, A)
    operation.append(op)
best_score = evalute(A)
print('\n'.join([' '.join(list(map(str,op))) for op in operation]))
# print('best_score = ' + str(best_score))
# print('----END----')
# take = time.time() - begin
# print(str(round(int(take * 1000),3)) + " ms")
0