結果

問題 No.43 野球の試合
ユーザー satanicsatanic
提出日時 2016-03-22 21:04:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,851 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 82,128 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 22:13:27
合計ジャッジ時間 1,815 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	class Pos{
	public:
		int row;
		int col;
		Pos(int i, int j) : row(i), col(j) {}
	};
	int n;
	std::cin >> n;
	std::vector<std::vector<int>> s(n, std::vector<int>(n));
	std::vector<std::vector<int>> evaluation(n, std::vector<int>(n));
	std::vector<Pos> position;
	std::vector<int> point(n, 0);
	int noBattleNum = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			char c;
			std::cin >> c;
			switch (c) {
			case '#': s[i][j] = 99; break;
			case 'o': s[i][j] =  1; break;
			case 'x': s[i][j] = -1; break;
			case '-':
				s[i][j] = 0;
				if (i < j) {
					++noBattleNum;
					position.push_back(Pos(i, j));
				}
				break;
			}
		}
	}
	int min = 10;
	for (int k = 0; k < std::pow(2, noBattleNum); ++k) {
		int tmp = k;
		evaluation = s;
		for (int i = 0; i < noBattleNum; ++i) {
			if (tmp % 2 == 1) {
				evaluation[position[i].col][position[i].row] =  1;
				evaluation[position[i].row][position[i].col] = -1;
			}
			else {
				evaluation[position[i].col][position[i].row] = -1;
				evaluation[position[i].row][position[i].col] =  1;
			}
			tmp /= 2;
		}
		for (int i = 0; i < n; ++i) {
			int sum = 0;
			for (int j = 0; j < n; ++j) {
				if (evaluation[i][j] == 99) continue;
				sum += evaluation[i][j];
			}
			point[i] = sum;
		}
		int pointZero = point[0];
		std::sort(point.begin(), point.end());
		std::reverse(point.begin(), point.end());
		std::vector<int> rank;
		for (int i = 0; i < n; ++i) {
			if (std::find(rank.begin(), rank.end(), point[i]) == rank.end()) {
				rank.push_back(point[i]);
			}
		}
		for (int i = 0; i < rank.size(); ++i) {
			if (rank[i] == pointZero) {
				min = (min > i + 1) ? i + 1 : min;
			}
		}
	}

	std::cout << min << "\n";

	return 0;
}
0