結果

問題 No.43 野球の試合
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-07 16:38:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,601 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 171,812 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 07:59:23
合計ジャッジ時間 2,156 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int N;
int ans = 6;

void dfs(string s[], int cnt) {
    if (cnt) {
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (s[i][j] == '-') {
                    s[i][j] = 'o';
                    s[j][i] = 'x';
                    dfs(s, cnt - 1);
                    s[i][j] = 'x';
                    s[j][i] = 'o';
                    dfs(s, cnt - 1);
                    s[i][j] = '-';
                    s[j][i] = '-';
                    return;
                }
            }
        }
    } else {
        vector<int> V;
        for (int i = 1; i < N; i++) {
            int win = 0;
            for (int j = 0; j < N; j++) {
                if (s[i][j] == 'o')
                    win++;
            }
            V.emplace_back(win);
        }
        sort(V.begin(), V.end(), greater<int>());

        int win = 0;
        for (int j = 0; j < N; j++) {
            if (s[0][j] == 'o')
                win++;
        }

        V.erase(unique(V.begin(), V.end()), V.end());

        int tmp = 1;
        for (int i = 0; i < V.size(); i++) {
            if (V[i] > win)
                tmp++;
            else {
                ans = min(ans, tmp);
                return;
            }
        }
        ans = min(ans, tmp);
    }
}

int main() {
    string s[6];
    cin >> N;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        cin >> s[i];
        for (auto& c : s[i])
            if (c == '-')
                cnt++;
    }
    cnt /= 2;

    dfs(s, cnt);
    cout << ans << endl;
}
0