結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,356 KB
testcase_01 AC 20 ms
8,368 KB
testcase_02 AC 20 ms
8,380 KB
testcase_03 AC 21 ms
8,408 KB
testcase_04 AC 19 ms
8,348 KB
testcase_05 AC 20 ms
8,476 KB
testcase_06 AC 22 ms
8,416 KB
testcase_07 AC 44 ms
8,412 KB
testcase_08 WA -
testcase_09 AC 20 ms
8,456 KB
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
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]))
        for i in range(n):
            if W[i][1] == 0:
                ans = min(ans, i + 1)
                return
    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