結果

問題 No.43 野球の試合
ユーザー DadarithmDadarithm
提出日時 2015-10-11 03:41:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 1,250 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 80,804 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 11:37:13
合計ジャッジ時間 2,083 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int N; vector<string> s; vector<pair<int, int>> pos;

int dfs(int depth)
{
	if (depth == 0)
	{
		vector<string> tmp = s;
		const string key = s[0];
		sort(s.begin(), s.end(), [](string i, string j){ return count(i.begin(), i.end(), 'o') > count(j.begin(), j.end(), 'o'); });
		for (int i = 0; i < N; ++i)
		{
			if (s[i] == key)
			{
				int counter = 0;
				for (int j = 0; j < i; ++j)
				{
					if (count(s[j].begin(), s[j].end(), 'o') == count(s[j + 1].begin(), s[j + 1].end(), 'o'))
						++counter;
				}
				s = tmp;
				return i + 1 - counter;
			}
		}
	}

	s[pos[depth - 1].first][pos[depth - 1].second] = 'o';
	s[pos[depth - 1].second][pos[depth - 1].first] = 'x';
	int a = dfs(depth - 1);
	s[pos[depth - 1].first][pos[depth - 1].second] = 'x';
	s[pos[depth - 1].second][pos[depth - 1].first] = 'o';
	int b = dfs(depth - 1);
	
	return min(a, b);
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		string tmp;
		cin >> tmp;
		s.push_back(tmp);
	}
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < i; ++j)
		{
			if (s[i][j] == '-')
				pos.push_back(pair<int, int>(i, j));
		}
	}

	cout << dfs(pos.size()) << endl;

	return 0;
}
0