結果
| 問題 |
No.43 野球の試合
|
| コンテスト | |
| ユーザー |
Tatsu_mr
|
| 提出日時 | 2024-10-04 19:17:05 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 5,000 ms |
| コード長 | 1,549 bytes |
| コンパイル時間 | 3,087 ms |
| コンパイル使用メモリ | 259,540 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-04 19:17:09 |
| 合計ジャッジ時間 | 3,668 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 |
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:48:5: warning: control reaches end of non-void function [-Wreturn-type]
48 | };
| ^
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for(long long i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
int main() {
int n;
cin >> n;
vector<vector<char>> s(n, vector<char>(n));
rep(i, n) {
rep(j, n) {
cin >> s[i][j];
}
}
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (s[i][j] == '-') {
v.emplace_back(i, j);
}
}
}
int sz = v.size();
auto calc = [&](vector<vector<char>> s) -> int {
vector<int> cnt(n, 0);
rep(i, n) rep(j, n) {
if (s[i][j] == 'o') {
cnt[i]++;
}
}
vector<vector<int>> lst(100);
rep(i, n) {
lst[cnt[i]].emplace_back(i);
}
int res = 1;
for (int i = 99; i >= 0; i--) {
for (int x : lst[i]) {
if (x == 0) {
return res;
}
}
if (lst[i].size() > 0) {
res++;
}
}
};
int ans = 100;
rep(bit, (1 << sz)) {
vector<vector<char>> t = s;
rep(i, sz) {
auto [x, y] = v[i];
if (bit & (1 << i)) {
t[x][y] = 'o';
t[y][x] = 'x';
} else {
t[x][y] = 'x';
t[y][x] = 'o';
}
}
ans = min(ans, calc(t));
}
cout << ans << endl;
}
Tatsu_mr