結果
| 問題 | No.43 野球の試合 | 
| コンテスト | |
| ユーザー |  data9824 | 
| 提出日時 | 2015-05-19 00:28:23 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 8 ms / 5,000 ms | 
| コード長 | 1,074 bytes | 
| コンパイル時間 | 655 ms | 
| コンパイル使用メモリ | 77,472 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-06 05:31:56 | 
| 合計ジャッジ時間 | 1,162 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <functional>
#include <limits>
#include <cstdlib>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<string> s(n), t(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		t[i] = s[i];
	}
	int games = n * (n - 1) / 2;
	int patterns = 1 << games;
	int minOrder = numeric_limits<int>::max();
	for (int bits = 0x0; bits < patterns; ++bits) {
		int mask = 0x1;
		for (int y = 1; y < n; ++y) {
			for (int x = 0; x < y; ++x) {
				if (s[x][y] == '-') {
					bool win = (bits & mask);
					t[x][y] = win ? 'o' : 'x';
					t[y][x] = win ? 'x' : 'o';
				}
				mask <<= 1;
			}
		}
		set<int, greater<int> > scores;
		for (int i = 1; i < n; ++i) {
			scores.insert(count(t[i].begin(), t[i].end(), 'o'));
		}
		int score0 = count(t[0].begin(), t[0].end(), 'o');
		int order = 1;
		for (set<int>::const_iterator it = scores.begin();
			it != scores.end() && score0 < *it;
			++it, ++order) {
		}
		minOrder = min(minOrder, order);
	}
	cout << minOrder << endl;
	return 0;
}
            
            
            
        