結果

問題 No.43 野球の試合
ユーザー けーむけーむ
提出日時 2020-03-25 14:55:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,942 bytes
コンパイル時間 3,010 ms
コンパイル使用メモリ 175,652 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 11:39:13
合計ジャッジ時間 2,766 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll f(vector<string> s, ll bit) {
    ll cur = 0, n = sz(s);
    rep(i, n) {
        rep(j, n) {
            if (s[i][j] == '-') {
                if ((bit & (1 << cur)) != 0) {
                    s[i][j] = 'o';
                    s[j][i] = 'x';
                }
                else {
                    s[i][j] = 'x';
                    s[j][i] = 'o';
                }
                cur++;
            }
        }
    }
    vector<ll> win(n, 0);
    rep(i, n) {
        rep(j, n) {
            if (s[i][j] == 'o') win[i]++;
        }
    }
    priority_queue<pair<ll, ll>> pq;
    rep(i, n) pq.push(make_pair(win[i], i));
    ll ans = 1;
    while(!pq.empty()) {
        auto p = pq.top(); pq.pop();
        if (p.first == win[0]) break;
        ans++;
    }
    // printf("bit=%lld\n", bit);
    // rep(i, n) rep(j, n) printf("%c%s", s[i][j], (j == (n - 1)) ? "\n" : "");
    // printf("\n");
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    ll cnt = 0;
    rep(i, n) {
        if (s[0][i] == '-') {
            s[0][i] = 'o';
            s[i][0] = 'x';
        }
    }
    rep(i, n) {
        rep(j, n) {
            if (s[i][j] == '-') cnt++;
        }
    }
    cnt /= 2;
    ll ans = LONG_LONG_MAX;
    if (cnt == 0) ans = f(s, 0);
    rep(i, 1 << cnt) {
        ans = min(ans, f(s, i));
    }
    cout << ans << endl;
    return 0;
}
0