結果
問題 | No.43 野球の試合 |
ユーザー | oooooba |
提出日時 | 2021-09-13 22:50:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 14 ms / 5,000 ms |
コード長 | 1,692 bytes |
コンパイル時間 | 1,364 ms |
コンパイル使用メモリ | 128,652 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-08 06:50:36 |
合計ジャッジ時間 | 2,050 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,384 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 14 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,376 KB |
testcase_09 | AC | 1 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
ソースコード
#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; }