結果

問題 No.5002 stick xor
ユーザー kerotonokerotono
提出日時 2018-05-27 21:45:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 748 ms / 1,000 ms
コード長 1,823 bytes
コンパイル時間 24,839 ms
実行使用メモリ 5,768 KB
スコア 1,343
最終ジャッジ日時 2018-05-27 21:45:53
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 720 ms
5,768 KB
testcase_01 AC 720 ms
5,712 KB
testcase_02 AC 716 ms
5,768 KB
testcase_03 AC 721 ms
5,764 KB
testcase_04 AC 724 ms
5,716 KB
testcase_05 AC 722 ms
5,764 KB
testcase_06 AC 728 ms
5,764 KB
testcase_07 AC 718 ms
5,764 KB
testcase_08 AC 717 ms
5,720 KB
testcase_09 AC 717 ms
5,716 KB
testcase_10 AC 726 ms
5,768 KB
testcase_11 AC 716 ms
5,764 KB
testcase_12 AC 727 ms
5,764 KB
testcase_13 AC 720 ms
5,760 KB
testcase_14 AC 714 ms
5,768 KB
testcase_15 AC 722 ms
5,716 KB
testcase_16 AC 748 ms
5,720 KB
testcase_17 AC 722 ms
5,712 KB
testcase_18 AC 722 ms
5,720 KB
testcase_19 AC 720 ms
5,764 KB
testcase_20 AC 726 ms
5,716 KB
testcase_21 AC 719 ms
5,716 KB
testcase_22 AC 725 ms
5,716 KB
testcase_23 AC 724 ms
5,768 KB
testcase_24 AC 719 ms
5,760 KB
testcase_25 AC 731 ms
5,716 KB
testcase_26 AC 718 ms
5,720 KB
testcase_27 AC 720 ms
5,764 KB
testcase_28 AC 715 ms
5,716 KB
testcase_29 AC 719 ms
5,720 KB
testcase_30 AC 743 ms
5,720 KB
testcase_31 AC 726 ms
5,720 KB
権限があれば一括ダウンロードができます

ソースコード

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, length):
    max_score = 0
    max_score_region = (0, 0, 0, 0)

    for y in range(N):
        for x in range(N - length + 1):
            if x == 0:
                score = sum(grid[y][:length])
            else:
                score -= grid[y][x - 1]
                score += grid[y][x + length - 1]
            if max_score < score:
                max_score = score
                max_score_region = (y, x, y, x + length - 1)
    for x in range(N):
        for y in range(N - length + 1):
            if y == 0:
                score = 0
                for i in range(length):
                    score += grid[i][x]
            else:
                score -= grid[y - 1][x]
                score += grid[y + length - 1][x]
            if max_score < score:
                max_score = score
                max_score_region = (y, x, y + length - 1, x)
    return max_score_region


def main():
    N, K = map(int, input().split())
    L = [[int(n), i] for i, n in enumerate(input().split())]
    L.sort(reverse=True, key=(lambda a: a[0]))

    grid = []
    for i in range(N):
        grid.append([])
        for c in input():
            grid[-1].append((c == '1') * 2 - 1)

    for k in range(K):
        L[k].append(get_region(N, grid, L[k][0]))

    L.sort(key=(lambda a: a[1]))

    for a in L:
        output(*[i + 1 for i in a[2]])


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