結果

問題 No.43 野球の試合
コンテスト
ユーザー Kude
提出日時 2020-09-06 23:04:00
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 649 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 206 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 80,768 KB
最終ジャッジ日時 2026-05-23 04:11:29
合計ジャッジ時間 1,675 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

pending = []
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
    for j in range(i):
        if s[i][j] == '-':
            pending.append((i, j))
def calc_score(s):
    wincnt = [si.count('o') for si in s]
    t = wincnt[0]
    ret = 1
    for x in set(wincnt):
        if x > t:
            ret += 1
    return ret
if not pending:
    print(calc_score(s))
    exit(0)
ans = n
for b in range(1 << len(pending)):
    stmp = [list(si) for si in s]
    for k, (i, j) in enumerate(pending):
        if b >> k & 1:
            stmp[i][j] = 'o'
        else:
            stmp[j][i] = 'o'
    ans = min(ans, calc_score(stmp))
print(ans)
0