結果

問題 No.43 野球の試合
ユーザー memmemmimemmemmi
提出日時 2018-06-24 15:44:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,311 bytes
コンパイル時間 1,012 ms
コンパイル使用メモリ 99,556 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 13:42:10
合計ジャッジ時間 1,821 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 main() {
	int n; cin >> n;
	vector<string> str(n);
	for (int i = 0; i < n; i++)cin >> str[i];

	vector<int>a, b;
	vector<int>win(n);

	for (int i = 0; i < n; i++)for (int j = 0; j < i; j++) {
		if (str[i][j] == '-') {
			a.push_back(i); b.push_back(j);
		}
		else if (str[i][j] == 'o')win[i]++;
		else win[j]++;
	}

	int ans = n;
	for (int i = 0; i < (1 << a.size()); i++) {//未対戦の勝敗全列挙
		vector<int> wt(win);
		for (int j = 0; j < a.size(); j++) {
			if ((i >> j) % 2)wt[a[j]]++;
			else wt[b[j]]++;
		}

		for (int k = 0; k < n; k++)wt[k] = wt[k] * n + k;
		sort(wt.begin(), wt.end());
		reverse(wt.begin(), wt.end());

		int place = 0, f = -1;
		for (int l = 0; l < n; l++) {
			int wnum = wt[l] / n;
			int team = wt[l] % n;
			if (f != wnum) {
				f = wnum; place++;
			}

			if (team == 0)ans = min(place, ans);
		}
	}
	cout << ans << endl;

	return 0;
}
0