結果

問題 No.43 野球の試合
ユーザー terasaterasa
提出日時 2022-06-06 18:20:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 204 ms / 5,000 ms
コード長 1,582 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 76,652 KB
最終ジャッジ日時 2023-10-21 03:39:49
合計ジャッジ時間 1,520 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
55,580 KB
testcase_01 AC 49 ms
55,580 KB
testcase_02 AC 45 ms
55,580 KB
testcase_03 AC 45 ms
55,580 KB
testcase_04 AC 45 ms
55,580 KB
testcase_05 AC 45 ms
55,580 KB
testcase_06 AC 92 ms
76,300 KB
testcase_07 AC 204 ms
76,652 KB
testcase_08 AC 45 ms
55,580 KB
testcase_09 AC 44 ms
55,580 KB
testcase_10 AC 45 ms
55,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


N = int(input())
S = [input()[:-1] for _ in range(N)]
rest = 0
for s in S:
    rest += s.count('-')
rest //= 2

ans = N
for s in range(1 << rest):
    cnt = 0
    A = [[None for _ in range(N)] for _ in range(N)]
    for i in range(N):
        for j in range(i, N):
            if S[i][j] == '-':
                A[i][j] = 'o' if s & (1 << cnt) else 'x'
                cnt += 1
            else:
                A[i][j] = S[i][j]
    for i in range(N):
        for j in range(i):
            if S[i][j] == '-':
                A[i][j] = 'x' if A[j][i] == 'o' else 'o'
            else:
                A[i][j] = S[i][j]
    wins = set()
    w0 = A[0].count('o')
    for i in range(N):
        wins.add(A[i].count('o'))
    acc = 1
    for w in wins:
        if w > w0:
            acc += 1
    ans = min(ans, acc)
print(ans)
0