結果

問題 No.43 野球の試合
ユーザー tonegawatonegawa
提出日時 2020-08-16 06:28:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,215 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 205,848 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 18:15:28
合計ジャッジ時間 2,730 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 18 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}	

0