結果

問題 No.43 野球の試合
ユーザー nnasennnasen
提出日時 2017-12-17 07:22:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,524 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 172,696 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 14:37:58
合計ジャッジ時間 2,327 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD 1000003
#define INF 100000000
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

bool jbo(bool *bo, int n) {
	FOR(i, 1, n) {
		if (!bo[i]) return false;
	}
	return true;
}

int np(VI r, int n) {
	set<int> st;
	REP(i, n) st.insert(r[i]);
	int sz = st.size();
	for (auto e : st) {
		if (r[0] == e) break;
		sz--;
	}
	return sz;
}

VI tr(VI r, int n, int t) {
	VI nr;
	REP(i, n) nr.push_back(r[i]);
	nr[t]++;
	return nr;
}

bool jox(VI r, int n, int p) {
	int a = np(tr(r, n, 0), n);
	int b = np(tr(r, n, p), n);
	if (a <= b) return 1;
	else return 0;
}

int main() {
	int n;
	cin >> n;
	char s[6][6] = {};
	VI r;
	REP(i, n) {
		int cnt = 0;
		REP(j, n) {
			cin >> s[i][j];
			if (s[i][j] == 'o') cnt++;
		}
		r.push_back(cnt);
	}
	int m = INF;
	int p = 0;
	bool bo[6] = { false };
	while (1) {
		FOR(i, 1, n) {
			if (!bo[i] && m >= r[i]) {
				m = r[i];
				p = i;
			}
		}
		FOR(i, 1, n) {
			if (s[p][i] == '-') {
				r[p]++;
				s[p][i] = 'o';
				s[i][p] = 'x';
				break;
			}
			if (i == n - 1) {
				bo[p] = true;
				m = INF;
			}
		}
		if (jbo(bo, n)) break;
	}
	REP(i, n) {
		if (s[0][i] == '-') {
			if (jox(r, n, i)) {
				r[0]++;
				s[0][i] = 'o';
				s[i][0] = 'x';
			}
			else {
				r[i]++;
				s[0][i] = 'x';
				s[i][0] = 'o';
			}
		}
	}
	cout << np(r, n) << endl;
	return 0;
}
0