結果

問題 No.43 野球の試合
ユーザー NotationNapNotationNap
提出日時 2015-05-06 10:31:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 854 bytes
コンパイル時間 1,440 ms
コンパイル使用メモリ 152,472 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-19 07:11:19
合計ジャッジ時間 2,209 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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