結果
| 問題 | No.43 野球の試合 | 
| コンテスト | |
| ユーザー |  misora192 | 
| 提出日時 | 2020-06-16 09:38:27 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 17 ms / 5,000 ms | 
| コード長 | 1,215 bytes | 
| コンパイル時間 | 1,771 ms | 
| コンパイル使用メモリ | 179,288 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-03 11:48:22 | 
| 合計ジャッジ時間 | 2,094 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
#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];
	
	vector<pii> v;
	for(int i = 0; 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;
}	
            
            
            
        