結果

問題 No.43 野球の試合
ユーザー 👑 rin204
提出日時 2022-01-20 21:10:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 807 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 75,820 KB
最終ジャッジ日時 2024-11-24 05:52:25
合計ジャッジ時間 1,086 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = [list(input()) for _ in range(n)]
lst = []    
for i in range(n):
    for j in range(i + 1, n):
        if S[i][j] == "-":
            lst.append((i, j))
ans = n
l = len(lst)
for bit in range(1 << l):
    for i in range(l):
        if bit >> i & 1:
            S[lst[i][0]][lst[i][1]] = "o"
            S[lst[i][1]][lst[i][0]] = "x"
        else:
            S[lst[i][0]][lst[i][1]] = "x"
            S[lst[i][1]][lst[i][0]] = "o"
    
    win = 0
    for j in range(1, n):
        if S[0][j] == "o":
            win += 1
    
    se = {win}
    for i in range(1, n):
        tot = 0
        for j in range(n):
            if S[i][j] == "o":
                tot += 1
        se.add(tot)
    ls = sorted(se, reverse = True)
    ans = min(ans, ls.index(win) + 1)
print(ans)
    
    
    
0