結果

問題 No.43 野球の試合
ユーザー tookunn_1213tookunn_1213
提出日時 2016-05-04 13:39:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 235 ms / 5,000 ms
コード長 637 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-15 11:16:59
合計ジャッジ時間 1,367 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,752 KB
testcase_01 AC 34 ms
10,880 KB
testcase_02 AC 35 ms
10,752 KB
testcase_03 AC 32 ms
10,752 KB
testcase_04 AC 33 ms
10,880 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 33 ms
10,880 KB
testcase_07 AC 235 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 31 ms
10,752 KB
testcase_10 AC 32 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(a,s,n):

	if n * n == a:
		rank,x,o = 1,0,0
		for i in range(n):
			if s[0][i] == 'x':
				x += 1
			elif s[0][i] == 'o':
				o += 1
		p = set([])
		for i in range(1,n):
			X,O = 0,0
			for j in range(n):
				if s[i][j] == 'x':
					X += 1
				elif s[i][j] == 'o':
					O += 1
			if O > o:
				p.add(O)
		return len(p) + 1
	y = a // n
	x = a % n

	if s[y][x] != '-':
		return dfs(a + 1,s,n)
	else:
		s[y][x] = 'x'
		s[x][y] = 'o'
		ret = dfs(a + 1,s,n)
		s[y][x] = 'o'
		s[x][y] = 'x'
		ret = min(ret,dfs(a + 1,s,n))
		s[y][x] = s[x][y] = '-'
		return ret
N = int(input())
s = [ list(input()) for i in range(N)]
print(dfs(0,s,N))
0