結果

問題 No.43 野球の試合
ユーザー kichirb3kichirb3
提出日時 2018-03-31 16:31:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 737 ms / 5,000 ms
コード長 1,525 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 11,072 KB
実行使用メモリ 8,584 KB
最終ジャッジ日時 2023-09-08 08:20:48
合計ジャッジ時間 1,974 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,492 KB
testcase_01 AC 19 ms
8,496 KB
testcase_02 AC 18 ms
8,576 KB
testcase_03 AC 18 ms
8,524 KB
testcase_04 AC 19 ms
8,584 KB
testcase_05 AC 18 ms
8,436 KB
testcase_06 AC 24 ms
8,444 KB
testcase_07 AC 737 ms
8,532 KB
testcase_08 AC 18 ms
8,580 KB
testcase_09 AC 18 ms
8,388 KB
testcase_10 AC 19 ms
8,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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


def update_status(i, result, remaining):
    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'


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 = deepcopy(status)
        update_status(i, result, 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(list(input().strip()))

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


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