結果

問題 No.43 野球の試合
ユーザー rlangevin
提出日時 2023-01-23 23:58:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 862 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,160 KB
最終ジャッジ日時 2024-06-25 17:39:05
合計ジャッジ時間 1,619 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = []
cnt = 0
D = []
for i in range(N):
    S.append(list(input()))
    for j in range(N):
        if S[i][j] == "-" and i < j:
            D.append((i, j))
            cnt += 1
    
if cnt == 0:
    L = []
    for i in range(N):
        L.append(S[i].count("o"))
    SL = sorted(list(set(L)))
    print(len(SL) - SL.index(L[0]))
    exit()
    
ans = 10 ** 18
for i in range(1 << cnt):
    A = [[0] * N for i in range(N)]
    for a in range(N):
        for b in range(N):
            A[a][b] = S[a][b]
    for j in range(cnt):
        x, y = D[j]
        if (i >> j) & 1:
            A[x][y] = "o"
            A[y][x] = "x"
        else:
            A[x][y] = "x"
            A[y][x] = "o"
    L = []
    for i in range(N):
        L.append(A[i].count("o"))
    SL = sorted(list(set(L)))
    ans = min(ans, len(SL) - SL.index(L[0]))
print(ans)
0