結果

問題 No.334 門松ゲーム
ユーザー ゆるくゆるく
提出日時 2019-05-01 03:48:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,232 bytes
コンパイル時間 879 ms
コンパイル使用メモリ 84,100 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 04:14:34
合計ジャッジ時間 1,866 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e9

int n;
vector<int> k;
int used[20];

bool is_kadomatsu(int x, int y, int z)
{
	if ( (k[x] > k[y] && k[z] > k[x]) || (k[z] > k[y] && k[x] > k[z]) ||
	     (k[x] < k[y] && k[z] < k[x]) || (k[z] < k[y] && k[x] < k[z]) ) {
	   	return true;
	} else {
		return false;
	}
}
int I, J, L;
bool dfs(int mask)
{
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int l = j + 1; l < n; l++) {
				if (~mask & (1 << i) && ~mask & (1 << j) && ~mask & (1 << l)) {
					if (is_kadomatsu(i, j, l)) {
						bool flg = dfs(mask | (1 << i ) | (1 << j) | (1 << l));
						if (!flg) {
							I = i;
							J = j;
							L = l;
							return true;
						}
					}
				}
			}
		}
	}
	return false;
}

int main()
{
	cin >> n;
	rep(i, n) {
		int t;
		cin >> t;
		k.push_back(t);
	}
	if (dfs(0)) {
		cout << I << " " << J << " " << L << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}
0