結果

問題 No.43 野球の試合
ユーザー masamasa
提出日時 2015-02-06 22:25:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,227 bytes
コンパイル時間 1,317 ms
コンパイル使用メモリ 74,176 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 14:43:05
合計ジャッジ時間 1,348 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int n_games;
vector< pair<int, int> > games;

int get_rank(vector<int> vec, int stat) {
	for (int i = 0; i < n_games; i++) {
		if ((stat >> i) & 1) {
			vec[ games[i].first ]++;
		} else {
			vec[ games[i].second ]++;
		}
	}
	int wins0 = vec[0];
	sort(vec.begin(), vec.end(), greater<int>());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	for (int i = 0; i < vec.size(); i++) {
		if (vec[i] == wins0) {
			return i + 1;
		}
	}
	return -1;
}

int main() {
	int n;

	cin >> n;
	vector<string> result(n);
	for (int i = 0; i < n; i++) {
		cin >> result[i];
	}

	games.clear();
	vector<int> wins(n, 0);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			switch (result[i][j]) {
			case '-':
				games.push_back(make_pair(i, j));
				break;
			case 'o':
				wins[i]++;
				break;
			case 'x':
				wins[j]++;
				break;
			default:
				break;
			}
		}
	}
	int ans = 1000;

	n_games = games.size();
	if (n_games == 0) {
		ans = get_rank(wins, 0);
	} else {
		for (int i = (1 << n_games) - 1; i >= 0; i--) {
			ans = min(ans, get_rank(wins, i));
		}
	}
	cout << ans << endl;
	return 0;
}
0