結果

問題 No.452 横着者のビンゴゲーム
ユーザー matsu7874matsu7874
提出日時 2016-12-02 03:39:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 486 ms / 3,000 ms
コード長 1,292 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 77,832 KB
最終ジャッジ日時 2024-11-28 21:18:19
合計ジャッジ時間 7,710 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int, input().split())
players = [[] for i in range(m)]

def rowize(matrix):
    size = len(matrix)
    rows = [matrix[i][:] for i in range(size)]
    for i in range(size):
        column = []
        for j in range(size):
            column.append(matrix[j][i])
        rows.append(column[:])
    diagonal = []
    for i in range(size):
        diagonal.append(matrix[i][i])
    rows.append(diagonal[:])
    diagonal = []
    for i in range(size):
        diagonal.append(matrix[i][size-i-1])
    rows.append(diagonal[:])
    return rows

def count_duplicated(a, b):
    cnt = 0
    i = 0
    j = 0
    while i<n and j<n:
        if a[i] < b[j]:
            i += 1
        elif a[i] == b[j]:
            cnt += 1
            i += 1
            j += 1
        else:
            j += 1
    return cnt

def max_x(duplicated):
    return 2*(n-duplicated) + (duplicated-1)

for p in range(m):
    card = []
    for i in range(n):
        card.append(list(map(int, input().split())))
    for row in rowize(card):
        players[p].append(sorted(row))

max_duplicated = 0
for i in range(m-1):
    for j in range(i+1, m):
        for p in players[i]:
            for q in players[j]:
                max_duplicated = max(max_duplicated, count_duplicated(p, q))
print(max_x(max_duplicated))
0