結果
問題 | No.43 野球の試合 |
ユーザー |
|
提出日時 | 2017-12-17 07:22:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,524 bytes |
コンパイル時間 | 1,703 ms |
コンパイル使用メモリ | 177,032 KB |
実行使用メモリ | 6,816 KB |
最終ジャッジ日時 | 2024-12-15 03:09:12 |
合計ジャッジ時間 | 2,364 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
#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 100000000using 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;}