結果

問題 No.452 横着者のビンゴゲーム
ユーザー rpy3cpp
提出日時 2017-04-25 22:38:44
言語 Python3
(3.7.4 + numpy 1.14.5 + scipy 1.1.0)
結果
AC  
実行時間 890 ms
コード長 1,255 Byte
コンパイル時間 50 ms
使用メモリ 8,140 KB
最終ジャッジ日時 2019-09-20 04:02:06

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
0_sample_1 AC 19 ms
5,600 KB
0_sample_2 AC 19 ms
5,604 KB
0_sample_3 AC 21 ms
5,600 KB
1_small_0 AC 25 ms
5,600 KB
1_small_1 AC 21 ms
5,604 KB
1_small_2 AC 25 ms
5,608 KB
1_small_3 AC 20 ms
5,600 KB
1_small_4 AC 20 ms
5,604 KB
1_small_5 AC 21 ms
5,600 KB
1_small_6 AC 20 ms
5,600 KB
1_small_7 AC 20 ms
5,604 KB
1_small_8 AC 21 ms
5,604 KB
1_small_9 AC 20 ms
5,608 KB
challenge01.txt AC 20 ms
5,608 KB
hand_0 AC 890 ms
8,140 KB
hand_1 AC 872 ms
8,072 KB
hand_2 AC 569 ms
6,912 KB
hand_3 AC 280 ms
5,676 KB
random_00 AC 118 ms
5,868 KB
random_01 AC 150 ms
5,644 KB
random_02 AC 169 ms
5,676 KB
random_03 AC 220 ms
6,304 KB
random_04 AC 182 ms
5,632 KB
random_05 AC 371 ms
6,688 KB
random_06 AC 79 ms
5,628 KB
random_07 AC 88 ms
5,612 KB
random_08 AC 260 ms
6,208 KB
random_09 AC 268 ms
5,904 KB
random_10 AC 132 ms
5,900 KB
random_11 AC 132 ms
5,676 KB
random_12 AC 284 ms
6,392 KB
random_13 AC 86 ms
5,672 KB
random_14 AC 102 ms
5,636 KB
random_15 AC 211 ms
5,676 KB
random_16 AC 160 ms
5,816 KB
random_17 AC 213 ms
5,676 KB
random_18 AC 109 ms
5,616 KB
random_19 AC 67 ms
5,628 KB
random_20 AC 816 ms
7,644 KB
random_21 AC 581 ms
6,912 KB
random_22 AC 603 ms
6,916 KB
random_23 AC 584 ms
6,916 KB
random_24 AC 584 ms
6,908 KB
random_25 AC 583 ms
6,912 KB
テストケース一括ダウンロード

ソースコード

diff #
def read_data():
    N, M = map(int, input().split())
    Cs = []
    for m in range(M):
        mat = [list(map(int, input().split())) for n in range(N)]
        Cs.append(mat)
    return N, M, Cs

def solve(N, M, Cs):
    mymax = max
    mylen = len
    maxC = mymax(mymax(mymax(c) for c in C) for C in Cs)
    Ds = C2D(N, M, Cs)
    record = 0
    bits = [0] * (maxC + 1)
    for i, D in enumerate(Ds):
        for d in D:
            for di in d:
                bits[di] = 1
            for E in Ds[i + 1:]:
                for e in E:
                    counts = mylen([1 for ei in e if bits[ei]])
#                    counts = mysum([bits[ei] for ei in e])
                    if counts > record:
                        record = counts
            for di in d:
                bits[di] = 0
        if record == N:
            return N - 1
    return 2 * N - 1 - record

def C2D(N, M, Cs):
    return [c2d(N, C) for C in Cs]

def c2d(N, C):
    d = []
    for c in C: d.append(c[:])
    Ct = list(zip(*C))
    for ct in Ct: d.append(list(ct))
    diagonal1 = [C[i][i] for i in range(N)]
    d.append(diagonal1)
    diagonal2 = [C[N - 1 - i][i] for i in range(N)]
    d.append(diagonal2)
    return d

N, M, Cs = read_data()
print(solve(N, M, Cs))
0