結果

問題 No.43 野球の試合
ユーザー lloyzlloyz
提出日時 2022-09-11 00:49:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 855 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 10,996 KB
実行使用メモリ 8,600 KB
最終ジャッジ日時 2023-08-18 05:28:15
合計ジャッジ時間 1,256 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,472 KB
testcase_01 AC 18 ms
8,532 KB
testcase_02 AC 17 ms
8,448 KB
testcase_03 AC 18 ms
8,372 KB
testcase_04 AC 18 ms
8,440 KB
testcase_05 AC 18 ms
8,572 KB
testcase_06 AC 20 ms
8,380 KB
testcase_07 AC 43 ms
8,540 KB
testcase_08 AC 18 ms
8,560 KB
testcase_09 AC 18 ms
8,436 KB
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy

n = int(input())
G = [list(input()) for _ in range(n)]

for i in range(n):
    if G[0][i] == '-':
        G[0][i] = 'o'
    if G[i][0] == '-':
        G[i][0] = 'x'

W = [[0, i] for i in range(n)]
M = []
for i in range(n):
    for j in range(n):
        if G[i][j] == 'o':
            W[i][0] += 1
        if i < j and G[i][j] == '-':
            M.append((i, j))

ans = n
g = len(M)
def func(W, i):
    global ans
    if i == g:
        W.sort(key=lambda x: (-x[0], x[1]))
        r = 1
        for i in range(n):
            if W[i][1] == 0:
                ans = min(ans, r)
                return
            if W[i][0] != W[i + 1][0]:
                r += 1
    x, y = M[i]
    W[x][0] += 1
    func(deepcopy(W), i + 1)
    W[x][0] -= 1
    W[y][0] += 1
    func(deepcopy(W), i + 1)
    W[y][0] -= 1

func(W, 0)
print(ans)
0