結果

問題 No.43 野球の試合
ユーザー lam6er
提出日時 2025-04-16 16:01:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,134 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 81,696 KB
実行使用メモリ 75,904 KB
最終ジャッジ日時 2025-04-16 16:07:01
合計ジャッジ時間 1,419 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = [input().strip().replace(' ', '') for _ in range(n)]

initial_wins = [0] * n
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if s[i][j] == 'o':
            initial_wins[i] += 1

remaining = []
for i in range(n):
    for j in range(i + 1, n):
        if s[i][j] == '-':
            remaining.append((i, j))

m = len(remaining)
min_rank = float('inf')

for mask in range(0, 1 << m):
    temp_wins = initial_wins.copy()
    for k in range(m):
        i, j = remaining[k]
        if (mask >> k) & 1:
            temp_wins[j] += 1
        else:
            temp_wins[i] += 1
    sorted_wins = sorted(temp_wins, reverse=True)
    current_rank = 1
    pos = 0
    found = False
    while pos < n and not found:
        current_win = sorted_wins[pos]
        count = 0
        while pos + count < n and sorted_wins[pos + count] == current_win:
            count += 1
        if temp_wins[0] == current_win:
            if current_rank < min_rank:
                min_rank = current_rank
            found = True
        current_rank += count
        pos += count

print(min_rank)
0