結果

問題 No.43 野球の試合
ユーザー memmemmimemmemmi
提出日時 2018-06-26 17:56:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,292 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 89,100 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 14:11:42
合計ジャッジ時間 1,400 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
char game[6][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