結果

問題 No.43 野球の試合
ユーザー NotationNapNotationNap
提出日時 2015-05-06 10:31:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 854 bytes
コンパイル時間 1,277 ms
コンパイル使用メモリ 152,404 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 07:11:41
合計ジャッジ時間 1,994 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))


int best_rank;
void f(int a, int b, vector<string>& t, const int n) {
	if (a == n) {
		vector<int> win(n);
		REP(i, n) REP(j, n) if (t[i][j] == 'o') win[i]++;
		set<int> s;
		for (int i = 1; i < n; i++) if (win[0] < win[i]) s.insert(win[i]);
		int rank = s.size() + 1;
		if (best_rank > rank) { best_rank = rank; }
		return;
	}
	int na = a;
	int nb = b;
	nb++;
	if (nb >= n) { na++; nb = 0; }

	if (t[a][b] == '-') {
		t[a][b] = 'o';
		t[b][a] = 'x';
		f(na, nb, t, n);
		t[a][b] = 'x';
		t[b][a] = 'o';
		f(na, nb, t, n);
		t[a][b] = '-';
		t[b][a] = '-';
	}
	else {
		f(na, nb, t, n);
	}
}

int main() {
	int n; cin >> n;
	vector<string> t(n);
	REP(i, n) cin >> t[i];
	best_rank = n;
	f(0, 0, t, n);
	cout << best_rank << endl;
}
0