結果

問題 No.43 野球の試合
ユーザー けーむけーむ
提出日時 2020-03-25 15:01:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,758 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 175,088 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-30 11:39:40
合計ジャッジ時間 2,560 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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]++;
        }
    }
    set<ll> rank;
    rep(i, n) rank.insert(win[i]);
    ll ans = 1;
    for(auto it = rank.rbegin(); it != rank.rend(); it++) {
        if (*it == 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) {
        rep(j, n) {
            if (s[i][j] == '-') cnt++;
        }
    }
    cnt /= 2;
    ll ans = LONG_LONG_MAX;
    rep(i, 1 << cnt) {
        ans = min(ans, f(s, i));
    }
    cout << ans << endl;
    return 0;
}
0