結果
| 問題 | No.43 野球の試合 | 
| コンテスト | |
| ユーザー |  maspy | 
| 提出日時 | 2020-02-02 12:26:01 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,405 ms / 5,000 ms | 
| コード長 | 840 bytes | 
| コンパイル時間 | 107 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 44,548 KB | 
| 最終ジャッジ日時 | 2024-09-18 20:35:28 | 
| 合計ジャッジ時間 | 7,916 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
import itertools
N = int(readline())
A = np.frombuffer(read(),'S1').reshape(N,-1)[:,:N]
base = np.zeros((N,N),np.int32)
base[A == b'#'] = 0
base[A == b'-'] = 0
base[A == b'o'] = 1
base[A == b'x'] = -1
base.flags.writeable = False
match = []
for i,j in itertools.combinations(range(N),2):
    if base[i][j] == 0:
        match.append((i,j))
n_match = len(match)
best = N
for p in itertools.product((True,False),repeat=n_match):
    A = base.copy()
    for (i,j),bl in zip(match, p):
        if not bl:
            i,j = j,i
        A[i,j] = 1
        A[j,i] = -1
    pts = A.sum(axis=1)
    me = pts[0]
    rank = len(np.unique(pts[pts > me])) + 1
    if best > rank:
        best = rank
print(best)
            
            
            
        