結果

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

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
0_sample_1 AC 19 ms
5,608 KB
0_sample_2 AC 19 ms
5,604 KB
0_sample_3 AC 19 ms
5,600 KB
1_small_0 AC 26 ms
5,604 KB
1_small_1 AC 19 ms
5,604 KB
1_small_2 AC 27 ms
5,604 KB
1_small_3 AC 21 ms
5,604 KB
1_small_4 AC 22 ms
5,604 KB
1_small_5 AC 22 ms
5,604 KB
1_small_6 AC 20 ms
5,600 KB
1_small_7 AC 21 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 1,405 ms
8,228 KB
hand_1 AC 1,363 ms
8,072 KB
hand_2 AC 887 ms
6,912 KB
hand_3 AC 343 ms
5,672 KB
random_00 AC 166 ms
5,864 KB
random_01 AC 190 ms
5,644 KB
random_02 AC 210 ms
5,672 KB
random_03 AC 327 ms
6,304 KB
random_04 AC 224 ms
5,628 KB
random_05 AC 559 ms
6,684 KB
random_06 AC 94 ms
5,628 KB
random_07 AC 107 ms
5,604 KB
random_08 AC 392 ms
6,204 KB
random_09 AC 374 ms
5,896 KB
random_10 AC 185 ms
5,900 KB
random_11 AC 174 ms
5,676 KB
random_12 AC 416 ms
6,396 KB
random_13 AC 112 ms
5,676 KB
random_14 AC 125 ms
5,632 KB
random_15 AC 289 ms
5,676 KB
random_16 AC 225 ms
5,816 KB
random_17 AC 269 ms
5,676 KB
random_18 AC 133 ms
5,620 KB
random_19 AC 78 ms
5,628 KB
random_20 AC 1,242 ms
7,648 KB
random_21 AC 882 ms
6,912 KB
random_22 AC 899 ms
6,916 KB
random_23 AC 894 ms
6,912 KB
random_24 AC 886 ms
6,908 KB
random_25 AC 893 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
    mysum = sum
    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 = len([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