結果

問題 No.43 野球の試合
ユーザー kichirb3kichirb3
提出日時 2018-03-31 19:16:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 171 ms / 5,000 ms
コード長 1,554 bytes
コンパイル時間 1,166 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 77,900 KB
最終ジャッジ日時 2023-09-08 10:16:30
合計ジャッジ時間 2,028 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,488 KB
testcase_01 AC 73 ms
71,704 KB
testcase_02 AC 73 ms
71,364 KB
testcase_03 AC 73 ms
71,704 KB
testcase_04 AC 75 ms
71,420 KB
testcase_05 AC 74 ms
71,540 KB
testcase_06 AC 83 ms
76,416 KB
testcase_07 AC 171 ms
77,900 KB
testcase_08 AC 72 ms
71,400 KB
testcase_09 AC 75 ms
71,460 KB
testcase_10 AC 73 ms
71,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.43 野球の試合
https://yukicoder.me/problems/no/43

"""
import sys
from sys import stdin
input = stdin.readline


def update_status(i, status, remaining):
    result = []
    for s in status:
        result.append(list(s))

    t = list(bin(i).zfill(len(remaining))[2:])
    for r, win_lose in zip(remaining, t):
        x, y = r[0], r[1]
        if win_lose == '1':
            result[y][x] = 'o'
            result[x][y] = 'x'
        else:
            result[y][x] = 'x'
            result[x][y] = 'o'
    return result


def solve(N, status):
    remaining = []
    for y in range(N):
        for x in range(y+1, N):
            if status[y][x] == '-':
                remaining.append([x, y])

    best_rank = N
    for i in range(2**len(remaining)):
        result = update_status(i, status, remaining)
        best_rank = min(best_rank, check_rank(N, result))
    return best_rank


def check_rank(N, result):
    # 他チームの勝ち星数をチェック
    winnings = []
    for r in result[1:]:
        w = r.count('o')
        if w not in winnings:
            winnings.append(w)
    # 自分のチームの勝ち星数と比較して順位を決定する
    my_winning = result[0].count('o')
    ans = 1
    for w in winnings:
        if w > my_winning:
            ans += 1
    return ans


def main(args):
    N = int(input())
    status = []
    for _ in range(N):
        status.append(input().strip())

    ans = solve(N, status)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0