結果

問題 No.43 野球の試合
ユーザー komori3komori3
提出日時 2017-09-26 21:43:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 2,399 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 81,140 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 14:20:07
合計ジャッジ時間 1,193 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
//#include "util.h"

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<pair<ll, ll>, ll> Plll;

#define PI 3.14159265358979323846
#define EPS 1e-6
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define CHAR_BIT 8
#define all(x) (x).begin(), (x).end()

template <typename _KTy, typename _Ty>
ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) {
	cout << "{" << m.first << ", " << m.second << "}";
	return ostr;
}

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
	if (v.empty()) {
		cout << "{ }";
		return ostr;
	}
	cout << "{" << v.front();
	for (auto itr = ++v.begin(); itr != v.end(); itr++) {
		cout << ", " << *itr;
	}
	cout << "}";
	return ostr;
}

template <typename _Ty>
ostream& operator << (ostream& ostr, const set<_Ty>& s) {
	if (s.empty()) {
		cout << "{ }";
		return ostr;
	}
	cout << "{" << *(s.begin());
	for (auto itr = ++s.begin(); itr != s.end(); itr++) {
		cout << ", " << *itr;
	}
	cout << "}";
	return ostr;
}

int N;
vector<char*> p, q;
int ans;

void rec(vector<string>& s, int pos)
{
	//全部埋まった
	if (pos == p.size()) {
		//順位算出
		vector<int> score(N, 0);
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (s[i][j] == 'o') score[i]++;
			}
		}
		int rank = 1;
		for (int w = N - 1; w >= 0; w--) {
			if (w == score[0]) break;

			bool flag = false;
			for (int t = 1; t < N; t++) {
				if (score[t] == w) flag = true;
			}

			if (flag) rank++;
		}

		if (ans > rank) ans = rank;

		return;
	}

	*p[pos] = 'o'; *q[pos] = 'x';
	rec(s, pos + 1);
	*p[pos] = 'x'; *q[pos] = 'o';
	rec(s, pos + 1);

}

int yuki0043() 
{
	cin >> N;

	vector<string> s(N);
	for (int i = 0; i < N; i++) cin >> s[i];

	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			if (s[i][j] != '-') continue;
			p.push_back(&s[i][j]);
			q.push_back(&s[j][i]);
		}
	}

	ans = N;
	rec(s, 0);

	cout << ans << endl;

	return 0;
}

int main()
{
	//clock_t start, end;
	//start = clock();

	yuki0043();

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}
0