結果
| 問題 | No.43 野球の試合 | 
| コンテスト | |
| ユーザー |  cherrypi59 | 
| 提出日時 | 2018-10-03 07:29:45 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 218 ms / 5,000 ms | 
| コード長 | 1,024 bytes | 
| コンパイル時間 | 86 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 11,008 KB | 
| 最終ジャッジ日時 | 2024-10-12 10:11:56 | 
| 合計ジャッジ時間 | 1,144 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
def cul(r):
    res = 0
    for i in r:
        if i == "o":
            res += 1
    return res
def main():
    n = int(input())
    s = [list(input()) for i in range(n)]
    score = [0] * n
    uncertain = []
    for i in range(n):
        for j in range(i+1, n):
            if s[i][j] == "-":
                uncertain.append((i, j))
    ans = n
    for i in range(2**len(uncertain)):
        for j in range(len(uncertain)):
            k, l = uncertain[j]
            if (i >> j) & 1:
                s[k][l], s[l][k] = "o", "x"
            else:
                s[k][l], s[l][k] = "x", "o"
        cnt, sc, score[0] = 1, set(), cul(s[0])
        for j in range(1, n):
            score[j] = cul(s[j])
            if score[0] < score[j] and score[j] not in sc:
                cnt += 1
                sc.add(score[j])
        ans = min(ans, cnt)
        for j in range(len(uncertain)):
            k, l = uncertain[j]
            s[k][l] = s[l][k] = "-"
    print(ans)
if __name__ == '__main__':
    main()
            
            
            
        