結果

問題 No.43 野球の試合
ユーザー ooooobaoooooba
提出日時 2021-09-13 22:29:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,644 bytes
コンパイル時間 1,266 ms
コンパイル使用メモリ 125,592 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-08 06:27:46
合計ジャッジ時間 9,876 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std; // NOLINT

size_t dfs(vector<string> &mat) {
    size_t ans = mat.size();
    bool found = false;
    for (size_t i = 0; i < mat.size(); ++i) {
        for (size_t j = i + 1; j < mat.size(); ++j) {
            if (mat[i][j] != '-')
                continue;
            found = true;
            mat[i][j] = 'o';
            mat[j][i] = 'x';
            auto ret = dfs(mat);
            ans = min(ans, ret);
            mat[i][j] = 'x';
            mat[j][i] = 'o';
            ret = dfs(mat);
            ans = min(ans, ret);
            mat[i][j] = '-';
            mat[j][i] = '-';
        }
    }
    if (found)
        return ans;
    vector<pair<size_t, size_t>> ps(mat.size());
    for (size_t i = 0; i < mat.size(); ++i) {
        ps[i].second = -i;
        for (size_t j = 0; j < mat.size(); ++j) {
            if (mat[i][j] == 'o')
                ++ps[i].first;
        }
    }
    sort(ps.rbegin(), ps.rend());
    if (ps[0].second == 0)
        return 1;
    ans = 1;
    for (size_t i = 1; i < mat.size(); ++i) {
        if (ps[i - 1].first != ps[i].first)
            ++ans;
        if (ps[i].second == 0)
            break;
    }
    return ans;
}

int main() {
    int32_t n;
    cin >> n;
    vector<string> mat(n);
    for (auto &&line : mat) {
        cin >> line;
    }
    cout << dfs(mat) << endl;
    return 0;
}
0