結果
問題 | No.43 野球の試合 |
ユーザー |
![]() |
提出日時 | 2020-06-16 09:32:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,303 bytes |
コンパイル時間 | 1,791 ms |
コンパイル使用メモリ | 180,176 KB |
実行使用メモリ | 6,940 KB |
最終ジャッジ日時 | 2024-07-03 11:48:19 |
合計ジャッジ時間 | 2,196 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 WA * 1 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=(0);i<(n);i++)using namespace std;typedef long long ll;typedef pair<int, int> pii;template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }int calc(vector<string> b){int a = 0;int n = b.size();rep(j, n) if(b[0][j] == 'o') a++;set<int> st;st.insert(a);rep(i, n - 1){int t = 0;rep(j, n) if(b[i+1][j] == 'o') t++;st.insert(t);}return st.size() - distance(st.begin(), st.lower_bound(a));}int main(){cin.tie(0);ios::sync_with_stdio(false);int n;cin >> n;vector<string> b(n);rep(i, n) cin >> b[i];rep(j, n-1) {if(b[0][j+1] == '-') {b[0][j+1] = 'o';b[j+1][0] = 'x';}}vector<pii> v;for(int i = 1; i < n; i++){for(int j = i + 1; j < n; j++){if(b[i][j] == '-'){v.push_back({i, j});}}}int k = v.size();if(k == 0){cout << calc(b) << endl;exit(0);}int ans = n;for(int i = 0; i < (1 << k); i++){rep(j, k){int r = v[j].first;int c = v[j].second;if((i >> j) & 1){b[r][c] = 'o';b[c][r] = 'x';}else{b[r][c] = 'x';b[c][r] = 'o';}}chmin(ans, calc(b));}cout << ans << endl;}