結果
| 問題 | No.43 野球の試合 | 
| コンテスト | |
| ユーザー |  maine_honzuki | 
| 提出日時 | 2020-05-07 16:38:53 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 5,000 ms | 
| コード長 | 1,601 bytes | 
| コンパイル時間 | 1,537 ms | 
| コンパイル使用メモリ | 173,644 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-03 09:30:15 | 
| 合計ジャッジ時間 | 2,062 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
#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;
}
            
            
            
        