結果

問題 No.43 野球の試合
ユーザー Yang33Yang33
提出日時 2018-04-11 16:19:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 3,197 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 177,164 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 04:05:10
合計ジャッジ時間 2,621 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 15 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int check(VS&)’ 内:
main.cpp:78:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   78 | }
      | ^

ソースコード

diff #

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/04/11  Problem: yukicoder 043  / Link: http://yukicoder.me/problems/no/043  ----- */
/* ------問題------

N個の野球チームがある。
K君はその0番目のチームに所属している。
すべてのチームが総当たりで試合をすることになった。
総当たりではすべてのチームがそれぞれ1試合ずつ試合を行う。
試合は勝ち負けが確定し引き分けは無いものとする。
順位は勝ち数が多い順で1位から決定していく。
勝ち数が同じであれば同じ順位のチームが複数のこともある。
また、順位は1位から決定し数字が抜けることは無い。
例えば1位が2チームでも次の順位は2位になる。
1位が2チームであるから次の順位が3位になるということは無い。
現在の勝ち負けの勝敗表が渡される。
もし残りの試合があれば残りの試合について試合の勝ち負けのパターンを考慮する。
K君の0番目のチームが最高で何位になりえるかを答えよ。


-----問題ここまで----- */
/* -----解説等-----

全探索

----解説ここまで---- */

int check(VS &t) {
	int N = SZ(t);
	vector<PII>rank(N, PII(0, 0));
	FOR(j, 0, N) {
		rank[j].second = j;
	}
	FOR(j, 0, N) {
		FOR(k, 0, N) {
			if (t[j][k] == 'o')rank[j].first++;
		}
	}
	RSORT(rank);
	int R = 1;
	int point=-1;
	FOR(j, 0, N) {
		if (point == -1) {
			point = rank[j].first;
		}
		else if (point == rank[j].first) {

		}
		else {
			R++;
			point = rank[j].first;
		}
		if (rank[j].second == 0)return R;

	}
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N; cin >> N;
	VS s(N);
	FOR(i, 0, N) {
		cin >> s[i];
	}
	vector<PII> pos;
	FOR(i, 0, N) {
		FOR(j, i + 1, N) {
			if (s[i][j] == '-') {
				pos.push_back(PII(i, j));
			}
		}
	}
	int ans = (SZ(pos)?N:check(s));

	FOR(i, 0, 1 << SZ(pos)) {
		VS t = s;
		FOR(j, 0, SZ(pos)) {
			if (i&(1 << j)) {
				t[pos[j].first][pos[j].second] = 'o';
				t[pos[j].second][pos[j].first] = 'x';
			}
			else {
				t[pos[j].first][pos[j].second] = 'x';
				t[pos[j].second][pos[j].first] = 'o';
			}
		}
		ans = min(ans, check(t));
	}
	cout << ans << "\n";

	return 0;
}
0