結果

問題 No.43 野球の試合
ユーザー furafura
提出日時 2020-04-14 04:15:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 625 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 203,572 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 22:54:09
合計ジャッジ時間 3,033 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 1 ms
6,548 KB
testcase_07 AC 7 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int n;
string B[6];

int dfs(int i,int j){
	if(i==n){
		vector<int> cnt(n);
		rep(i,n) rep(j,n) if(B[i][j]=='o') cnt[i]++;
		int res=1;
		for(int x=n-1;x>cnt[0];x--) if(count(cnt.begin(),cnt.end(),x)>0) res++;
		return res;
	}

	if(j==n) return dfs(i+1,0);
	if(B[i][j]!='-') return dfs(i,j+1);

	int res=n;
	B[i][j]='o'; B[j][i]='x';
	res=min(res,dfs(i,j+1));
	B[i][j]='x'; B[j][i]='o';
	res=min(res,dfs(i,j+1));
	B[i][j]='-'; B[j][i]='-';
	return res;
}

int main(){
	cin>>n;
	rep(i,n) cin>>B[i];

	cout<<dfs(0,0)<<'\n';

	return 0;
}
0