結果
| 問題 | No.43 野球の試合 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-09-13 22:50:00 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 14 ms / 5,000 ms | 
| コード長 | 1,692 bytes | 
| コンパイル時間 | 1,618 ms | 
| コンパイル使用メモリ | 127,108 KB | 
| 最終ジャッジ日時 | 2025-01-24 13:46:37 | 
| ジャッジサーバーID (参考情報) | judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
#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
int main() {
    int32_t n;
    cin >> n;
    vector<string> mat(n);
    for (auto &&line : mat) {
        cin >> line;
    }
    vector<pair<int32_t, int32_t>> ps;
    for (auto i = 0; i < n; ++i) {
        for (auto j = i + 1; j < n; ++j) {
            if (mat[i][j] == '-')
                ps.push_back({i, j});
        }
    }
    int32_t ans = n;
    for (auto b = 0; b < (1 << ps.size()); ++b) {
        auto tmat = mat;
        for (size_t i = 0; i < ps.size(); ++i) {
            auto [x, y] = ps[i];
            if ((b >> i) & 0b1) {
                tmat[x][y] = 'o';
                tmat[y][x] = 'x';
            } else {
                tmat[x][y] = 'x';
                tmat[y][x] = 'o';
            }
        }
        vector<pair<int32_t, int32_t>> vis(n);
        for (auto i = 0; i < n; ++i) {
            vis[i].second = -i;
            for (auto j = 0; j < n; ++j) {
                if (tmat[i][j] == 'o')
                    ++vis[i].first;
            }
        }
        sort(vis.rbegin(), vis.rend());
        if (vis[0].second == 0)
            ans = 1;
        auto t = 1;
        for (auto i = 1; i < n; ++i) {
            if (vis[i - 1].first != vis[i].first)
                ++t;
            if (vis[i].second == 0) {
                ans = min(ans, t);
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
            
            
            
        