結果

問題 No.43 野球の試合
ユーザー pekempeypekempey
提出日時 2016-11-19 23:55:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 236 ms / 5,000 ms
コード長 548 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 7,948 KB
最終ジャッジ日時 2023-08-18 03:54:56
合計ジャッジ時間 1,189 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,768 KB
testcase_01 AC 16 ms
7,820 KB
testcase_02 AC 16 ms
7,788 KB
testcase_03 AC 16 ms
7,804 KB
testcase_04 AC 17 ms
7,948 KB
testcase_05 AC 17 ms
7,820 KB
testcase_06 AC 17 ms
7,804 KB
testcase_07 AC 236 ms
7,796 KB
testcase_08 AC 16 ms
7,852 KB
testcase_09 AC 16 ms
7,752 KB
testcase_10 AC 16 ms
7,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

g = [list(input()) for _ in range(N)]

def dfs(g, yx):
	if yx == N * N:
		win = [0] * N
		for i in range(N):
			for j in range(N):
				if g[i][j] == 'o':
					win[i] += 1
		res = 0
		for x in set(win):
			if win[0] == x:
				return len(set(win)) - res
			res += 1

	y, x = yx // N, yx % N
	if g[y][x] != '-':
		return dfs(g, yx + 1)

	res = 100

	g[y][x], g[x][y] = 'o', 'x'
	res = min(res, dfs(g, yx + 1))

	g[y][x], g[x][y] = 'x', 'o'
	res = min(res, dfs(g, yx + 1))

	g[y][x], g[x][y] = '-', '-'

	return res

print(dfs(g, 0))
0