結果

問題 No.43 野球の試合
ユーザー furafura
提出日時 2020-04-14 04:00:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 210,420 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 22:24:46
合計ジャッジ時間 2,989 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,548 KB
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

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]++;

		vector<pair<int,int>> p(n);
		rep(i,n) p[i]={-cnt[i],i};
		sort(p.begin(),p.end());
		return find(p.begin(),p.end(),make_pair(-cnt[0],0))-p.begin()+1;
	}

	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];

	rep(j,n) if(B[0][j]=='-') {
		B[0][j]='o';
		B[j][0]='x';
	}

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

	return 0;
}
0