結果

問題 No.5002 stick xor
ユーザー kerotonokerotono
提出日時 2018-05-27 14:15:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,409 bytes
コンパイル時間 30,118 ms
実行使用メモリ 5,732 KB
スコア 0
最終ジャッジ日時 2018-05-27 14:15:35
ジャッジサーバーID
(参考情報)
judge9 /
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#!python
# -*- coding: utf-8 -*-


PRINT_STR = ""


def output(y1, x1, y2, x2):
    global PRINT_STR
    PRINT_STR += "{} {} {} {}\n".format(y1, x1, y2, x2)


def updete(grid, y1, x1, y2, x2):
    if y1 == y2:
        y = y1
        for x in range(x1, x2 + 1):
            grid[y][x] *= -1
    elif x1 == x2:
        x = x1
        for y in range(y1, y2 + 1):
            grid[y][x] *= -1


def get_region(N, grid):
    max_score = 0
    max_score_length = 0
    max_score_region = (0, 0, 0, 0)

    for y in range(N):
        s = 0
        length = 0
        min_ = 0
        max_ = 0
        for x in range(N):
            s += grid[y][x]
            length += 1

            if max_ < s:
                max_ = s
            if s < min_:
                min_ = s
                max_ = min_
                length = 0

            score = max_ - min_
            if max_score < score:
                max_score = score
                max_score_length = length
                max_score_region = (y, x - length + 1, y, x)
            elif max_score == score and max_score_length > length:
                max_score = score
                max_score_length = length
                max_score_region = (y, x - length + 1, y, x)
    for x in range(N):
        s = 0
        length = 0
        min_ = 0
        max_ = 0
        for y in range(N):
            s += grid[y][x]
            length += 1

            if max_ < s:
                max_ = s
            if s < min_:
                min_ = s
                max_ = min_
                length = 0

            score = max_ - min_
            if max_score < score:
                max_score = score
                max_score_length = length
                max_score_region = (y - length + 1, x, y, x)
            elif max_score == score and max_score_length > length:
                max_score = score
                max_score_length = length
                max_score_region = (y - length + 1, x, y, x)
    return max_score_region


def main():
    N, K = map(int, input().split())
    L = list(map(int, input().split()))

    grid = []
    for i in range(N):
        grid.append([])
        for c in input():
            grid[-1].append((c == '1') * 2 - 1)
    for k in range(K):
        region = get_region(N, grid)
        updete(grid, *region)
        output(*[i + 1 for i in region])


if __name__ == '__main__':
    main()
    print(PRINT_STR)
0