結果

問題 No.334 門松ゲーム
ユーザー masamasa
提出日時 2016-01-15 23:49:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,568 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 69,036 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:41:23
合計ジャッジ時間 1,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>

using namespace std;

vector<int> k;
vector<int> kados;

const int DD = 0;
const int EE = 1;

bool isKadomatu(int a, int b, int c) {
	if (a == b || b == c || c == a) {
		return false;
	}
	if (max({a, b, c}) == b || min({a, b, c}) == b) {
		return true;
	}
	return false;
}

void showKadoIdx(int kado) {
	int n_show = 0;
	for (int i = 0; i < 12; i++) {
		if ((kado >> i) & 1) {
			cout << i;
			n_show++;
			if (n_show == 3) {
				break;
			}
			cout << " ";
		}
	}
	cout << endl;
}

bool win(int kado, int used, int who) {
	// printf("who %d: kado %d used %d\n", who, kado, used);
	int now = kado | used;
	for (int i = 0; i < kados.size(); i++) {
		if ((kados[i] & now) > 0) {
			continue;
		}
		// printf("used %d -> %d\n", used, now);
		bool stat = win(kados[i], now, who == DD ? EE : DD);
		if (who == DD && !stat) {return false;}
		if (who == EE && stat)  {return true;}
	}

	if (who == DD) {
		return true;
	} else {
		return false;
	}
}

int main() {
	int n;

	cin >> n;
	k.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> k[i];
	}

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int l = j + 1; l < n; l++) {
				if (isKadomatu(k[i], k[j], k[l])) {
					kados.emplace_back((1 << i) | (1 << j) | (1 << l));
				}
			}
		}
	}

	for (int i = 0; i < kados.size(); i++) {
		int used = 0;
		if (win(kados[i], used, DD)) {
			showKadoIdx(kados[i]);
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}
0