結果

問題 No.43 野球の試合
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-05-23 15:39:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,020 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 60,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 09:11:14
合計ジャッジ時間 1,216 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 8 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int search(int)’:
main.cpp:50:1: warning: control reaches end of non-void function [-Wreturn-type]
   50 | }
      | ^

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

#define NMAX 6

int N;
string s[NMAX];

int calc(){
	int w[NMAX] = { 0 };
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			if (s[i][j] == 'o') w[i]++;
		}
	}

	for (int i = 1;; i++){
		int maxc = -1;
		for (int j = 0; j < N; j++) maxc = max(maxc, w[j]);
		for (int j = 0; j < N; j++){
			if (maxc == w[j]){
				if (j == 0) return i;
				w[j] = -2;
			
			}
		}
	}
}
int search(int c){
	if (c == 0) return calc();
	int maxc = NMAX+1;
	for (int i = 1; i < N; i++){
		for (int j = 0; j < i; j++){
			if (s[i][j] == '-'){
				s[i][j] = 'o';
				s[j][i] = 'x';
				maxc = min(search(c - 2),maxc);
				s[i][j] = 'x';
				s[j][i] = 'o';
				maxc = min(search(c - 2), maxc);
				s[i][j] = '-';
				s[j][i] = '-';
				return maxc;
			}
		}
	}
}

int main(){
	
	int c = 0;

	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> s[i];
		for (int j = 0; j < s[i].size(); j++){
			if (s[i][j] == '-') c++;
		}
	}

	cout << search(c) << endl;
}
0