結果

問題 No.452 横着者のビンゴゲーム
ユーザー rpy3cpprpy3cpp
提出日時 2017-04-25 22:40:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 721 ms / 3,000 ms
コード長 1,254 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 11,120 KB
実行使用メモリ 11,036 KB
最終ジャッジ日時 2023-10-11 12:53:03
合計ジャッジ時間 10,137 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,216 KB
testcase_01 AC 16 ms
8,328 KB
testcase_02 AC 15 ms
8,376 KB
testcase_03 AC 20 ms
8,400 KB
testcase_04 AC 17 ms
8,256 KB
testcase_05 AC 20 ms
8,412 KB
testcase_06 AC 15 ms
8,320 KB
testcase_07 AC 17 ms
8,396 KB
testcase_08 AC 18 ms
8,380 KB
testcase_09 AC 16 ms
8,364 KB
testcase_10 AC 16 ms
8,220 KB
testcase_11 AC 17 ms
8,216 KB
testcase_12 AC 16 ms
8,440 KB
testcase_13 AC 16 ms
8,284 KB
testcase_14 AC 721 ms
10,920 KB
testcase_15 AC 700 ms
11,036 KB
testcase_16 AC 476 ms
9,556 KB
testcase_17 AC 271 ms
8,140 KB
testcase_18 AC 103 ms
8,496 KB
testcase_19 AC 139 ms
8,584 KB
testcase_20 AC 158 ms
8,448 KB
testcase_21 AC 183 ms
9,180 KB
testcase_22 AC 170 ms
8,004 KB
testcase_23 AC 295 ms
9,540 KB
testcase_24 AC 74 ms
8,576 KB
testcase_25 AC 83 ms
8,400 KB
testcase_26 AC 223 ms
8,936 KB
testcase_27 AC 239 ms
8,672 KB
testcase_28 AC 112 ms
8,636 KB
testcase_29 AC 119 ms
8,624 KB
testcase_30 AC 236 ms
9,248 KB
testcase_31 AC 75 ms
8,124 KB
testcase_32 AC 90 ms
8,380 KB
testcase_33 AC 188 ms
8,716 KB
testcase_34 AC 140 ms
8,660 KB
testcase_35 AC 191 ms
8,580 KB
testcase_36 AC 101 ms
8,560 KB
testcase_37 AC 62 ms
8,076 KB
testcase_38 AC 647 ms
10,424 KB
testcase_39 AC 483 ms
9,508 KB
testcase_40 AC 482 ms
9,628 KB
testcase_41 AC 484 ms
9,708 KB
testcase_42 AC 483 ms
9,660 KB
testcase_43 AC 484 ms
9,580 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 = 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