結果
問題 | No.43 野球の試合 |
ユーザー |
![]() |
提出日時 | 2018-03-31 16:31:03 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 819 ms / 5,000 ms |
コード長 | 1,525 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-06-26 01:39:50 |
合計ジャッジ時間 | 1,899 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
# -*- 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:])