結果
問題 | No.43 野球の試合 |
ユーザー |
![]() |
提出日時 | 2025-01-08 00:22:54 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 5,000 ms |
コード長 | 1,162 bytes |
コンパイル時間 | 5,075 ms |
コンパイル使用メモリ | 291,004 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-08 00:23:00 |
合計ジャッジ時間 | 6,208 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n; cin >> n; vector Grid(n, vector<char>(n)); rep(i, n) rep(j, n) cin >> Grid[i][j]; vector<pair<int, int>> id(0); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { id.push_back({ i, j }); } } assert(id.size() <= 15); int ans = 1e9; rep(bit, 1 << id.size()) { bool ok = true; vector<int> cnt(n, 0); rep(i, id.size()) { auto [x, y] = id[i]; if (bit & (1 << i)) { if (Grid[x][y] == 'o' || Grid[x][y] == '-') ++cnt[x]; else ok = false; } else { if (Grid[x][y] == 'x' || Grid[x][y] == '-') ++cnt[y]; else ok = false; } } if (ok) { set<int> st(cnt.begin(), cnt.end()); map<int, int> mp; int cur = 0; for (auto x : st) mp[x] = cur++; ans = min(ans, cur - mp[cnt[0]]); } } cout << ans << endl; return 0; }