結果

問題 No.5002 stick xor
ユーザー GrayCoderGrayCoder
提出日時 2018-06-01 21:48:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 897 ms / 1,000 ms
コード長 1,741 bytes
コンパイル時間 28,044 ms
実行使用メモリ 6,032 KB
スコア 43,171
最終ジャッジ日時 2018-06-01 21:49:03
ジャッジサーバーID
(参考情報)
judge8 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 781 ms
6,016 KB
testcase_01 AC 745 ms
6,020 KB
testcase_02 AC 842 ms
6,016 KB
testcase_03 AC 763 ms
6,016 KB
testcase_04 AC 811 ms
6,020 KB
testcase_05 AC 763 ms
6,020 KB
testcase_06 AC 840 ms
6,012 KB
testcase_07 AC 876 ms
6,016 KB
testcase_08 AC 782 ms
6,020 KB
testcase_09 AC 839 ms
6,020 KB
testcase_10 AC 820 ms
6,016 KB
testcase_11 AC 810 ms
6,032 KB
testcase_12 AC 841 ms
6,020 KB
testcase_13 AC 796 ms
6,016 KB
testcase_14 AC 813 ms
6,020 KB
testcase_15 AC 764 ms
6,020 KB
testcase_16 AC 876 ms
6,016 KB
testcase_17 AC 835 ms
6,016 KB
testcase_18 AC 823 ms
6,016 KB
testcase_19 AC 826 ms
6,016 KB
testcase_20 AC 749 ms
6,016 KB
testcase_21 AC 855 ms
6,012 KB
testcase_22 AC 791 ms
6,020 KB
testcase_23 AC 887 ms
6,020 KB
testcase_24 AC 822 ms
6,020 KB
testcase_25 AC 768 ms
6,020 KB
testcase_26 AC 866 ms
6,016 KB
testcase_27 AC 897 ms
6,020 KB
testcase_28 AC 870 ms
6,020 KB
testcase_29 AC 791 ms
6,020 KB
testcase_30 AC 789 ms
6,016 KB
testcase_31 AC 829 ms
6,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    grid = [[0] * (N + 2)]
    apnd = grid.append
    for n in A:
        apnd([0] + n + [0])
    apnd([0] * (N + 2))

    for l in L:
        case1 = search1(l, grid)
        if l == 1:
            case2 = case1
        else:
            grid = list(map(list, zip(*grid)))
            case2 = search1(l, grid)

        if case1[0] >= case2[0]:
            if l > 1:
                grid = list(map(list, zip(*grid)))
            _, row1, col1, row2, col2 = case1
            line = grid[row1][col1:col2]
            grid[row1][col1:col2] = list(map(lambda x: int(not x), line))
            print(row1, col1, row2, col2 - 1)
        else:
            _, row1, col1, row2, col2 = case2
            line = grid[row1][col1:col2]
            grid[row1][col1:col2] = list(map(lambda x: int(not x), line))
            row1, col1 = col1, row1
            row2, col2 = col2, row2
            grid = list(map(list, zip(*grid)))
            print(row1, col1, row2 - 1, col2)

def search1(l, grid):
    max1 = 0
    for i in range(1, N + 1):
        cnt = 0
        for j in range(1, N + 1):
            if grid[i][j]:
                cnt += 1
            if j >= l:
                col1 = (j - l) + 1
                cnt -= grid[i][j-l]
                if max1 <= cnt and \
                        grid[i][col1] != grid[i][col1-1] and \
                        grid[i][col1+l-1] != grid[i][col1+l]:
                    max1 = cnt
                    ret = (max1, i, col1, i, col1 + l)
                if cnt == l and not grid[i][col1-1] and not grid[i][col1+l]:
                    return ret
    return ret

N, K = map(int, input().split())
L = tuple(map(int, input().split()))
A = [list(map(int, list(input()))) for _ in [0] * N]
main()
0