結果

問題 No.5002 stick xor
ユーザー tookunn_1213tookunn_1213
提出日時 2018-05-26 15:57:59
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,239 bytes
コンパイル時間 42,454 ms
スコア 0
最終ジャッジ日時 2018-05-26 15:58:44
ジャッジサーバーID
(参考情報)
judge9 /
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
権限があれば一括ダウンロードができます

ソースコード

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 = 200
for k in range(K):
    hq = []
    for i in range(P):
        x = random.randint(0, N-L[k])
        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])
        # print(horizon_cnt,end=" ")
        # print(vertical_cnt)
        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 x in range(N-L[k]+1):
    #     for y in range(N-L[k]+1):
    #         horizon_cnt = count_black_horizon(A, x, y, L[k])
    #         vertical_cnt = count_black_vertical(A, x, y, L[k])
    #         # print(horizon_cnt,end=" ")
    #         # print(vertical_cnt)
    #         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