結果
問題 | No.43 野球の試合 |
ユーザー |
![]() |
提出日時 | 2020-03-25 14:55:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,942 bytes |
コンパイル時間 | 1,769 ms |
コンパイル使用メモリ | 171,596 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-01 23:52:40 |
合計ジャッジ時間 | 2,198 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 5 WA * 2 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)#define all(x) (x).begin(), (x).end()#define sz(x) ((ll)(x).size())#define len(x) ((ll)(x).length())ll f(vector<string> s, ll bit) {ll cur = 0, n = sz(s);rep(i, n) {rep(j, n) {if (s[i][j] == '-') {if ((bit & (1 << cur)) != 0) {s[i][j] = 'o';s[j][i] = 'x';}else {s[i][j] = 'x';s[j][i] = 'o';}cur++;}}}vector<ll> win(n, 0);rep(i, n) {rep(j, n) {if (s[i][j] == 'o') win[i]++;}}priority_queue<pair<ll, ll>> pq;rep(i, n) pq.push(make_pair(win[i], i));ll ans = 1;while(!pq.empty()) {auto p = pq.top(); pq.pop();if (p.first == win[0]) break;ans++;}// printf("bit=%lld\n", bit);// rep(i, n) rep(j, n) printf("%c%s", s[i][j], (j == (n - 1)) ? "\n" : "");// printf("\n");return ans;}int main() {cin.tie(0);ios::sync_with_stdio(false);// ifstream in("input.txt");// cin.rdbuf(in.rdbuf());ll n;cin >> n;vector<string> s(n);rep(i, n) cin >> s[i];ll cnt = 0;rep(i, n) {if (s[0][i] == '-') {s[0][i] = 'o';s[i][0] = 'x';}}rep(i, n) {rep(j, n) {if (s[i][j] == '-') cnt++;}}cnt /= 2;ll ans = LONG_LONG_MAX;if (cnt == 0) ans = f(s, 0);rep(i, 1 << cnt) {ans = min(ans, f(s, i));}cout << ans << endl;return 0;}