結果

問題 No.334 門松ゲーム
ユーザー data9824data9824
提出日時 2016-02-03 01:46:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 69,224 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 18:47:49
合計ジャッジ時間 1,388 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using namespace std;

vector<int> k;
vector<bool> removed;
size_t index1;
size_t index2;
size_t index3;

bool turn() {
	for (size_t i1 = 0; i1 < k.size() - 2; ++i1) {
		if (removed[i1]) {
			continue;
		}
		for (size_t i2 = i1 + 1; i2 < k.size() - 1; ++i2) {
			if (removed[i2]) {
				continue;
			}
			for (size_t i3 = i2 + 1; i3 < k.size(); ++i3) {
				if (removed[i3]) {
					continue;
				}
				if (k[i1] != k[i2] && k[i2] != k[i3] && (
					max(k[i1], max(k[i2], k[i3])) == k[i2] || 
					min(k[i1], min(k[i2], k[i3])) == k[i2])) {
					removed[i1] = true;
					removed[i2] = true;
					removed[i3] = true;
					bool win = !turn();
					removed[i1] = false;
					removed[i2] = false;
					removed[i3] = false;
					if (win) {
						index1 = i1;
						index2 = i2;
						index3 = i3;
						return true;
					}
				}
			}
		}
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	k.resize(n);
	removed.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
	}
	bool win = turn();
	if (win) {
		cout << index1 << " " << index2 << " " << index3 << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}
0