結果

問題 No.43 野球の試合
ユーザー memmemmimemmemmi
提出日時 2018-06-26 18:04:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,291 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 91,044 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 14:11:56
合計ジャッジ時間 1,368 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int n;
string game[6];

int dfs(int x) {
	if (x == 0) {
		int win[6] = {0};
		for (int i = 0; i < n; i++)for (int j = 0; j < n; j++) {
			win[i] += game[i][j] == 'o';
		}
		int ret = 0;
		for (int i = n; i--;) {
			for (int j = 0; j < n; j++)
				if (win[j] == i) { ret++; break; }
			if (win[0] == i) return ret;
		}
	}
	else {
		int ret = INT_MAX;
		for (int i = 0; i < n; i++)for (int j = 0; j < i; j++) {
			if (game[i][j] == '-') {
				game[i][j] = 'o'; game[j][i] = 'x';
				ret = min(ret, dfs(x - 1));
				game[i][j] = 'x'; game[j][i] = 'o';
				ret = min(ret, dfs(x - 1));
				game[i][j] = game[j][i] = '-';
				return ret;
			}
		}
		return ret;
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> game[i];
	int bar = 0;
	for (int i = 0; i < n; i++)for (int j = 0; j < i; j++)bar += game[i][j] == '-';
	cout << dfs(bar) << endl;
	return 0;
}
0