結果

問題 No.43 野球の試合
ユーザー lloyzlloyz
提出日時 2022-09-11 00:51:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 807 ms / 5,000 ms
コード長 745 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 8,596 KB
最終ジャッジ日時 2023-08-18 05:29:19
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,388 KB
testcase_01 AC 18 ms
8,432 KB
testcase_02 AC 19 ms
8,420 KB
testcase_03 AC 19 ms
8,404 KB
testcase_04 AC 20 ms
8,416 KB
testcase_05 AC 19 ms
8,504 KB
testcase_06 AC 25 ms
8,384 KB
testcase_07 AC 807 ms
8,480 KB
testcase_08 AC 20 ms
8,596 KB
testcase_09 AC 19 ms
8,432 KB
testcase_10 AC 19 ms
8,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy

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

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