結果

問題 No.334 門松ゲーム
ユーザー fiordfiord
提出日時 2016-01-15 22:52:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 164,176 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:28:02
合計ジャッジ時間 2,042 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 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 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 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 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
bool ok(int a,int b,int c){
	if(a==b||b==c||c==a)	return false;
	int m=max(a,max(b,c)),M=min(a,min(b,c));
	if(b==m||b==M)	return true;
	return false;
}
bool dfs(vector<int> l){
	int n=l.size();
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if(ok(l[i],l[j],l[k])){
					vector<int> next=l;
					next.erase(next.begin()+k);
					next.erase(next.begin()+j);
					next.erase(next.begin()+i);
					if(!dfs(next))	return true;
				}
			}
		}
	}
	return false;
}
int main(){
	int n;	cin>>n;
	vector<int> l(n);
	for(int i=0;i<n;i++)	cin>>l[i];
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if(ok(l[i],l[j],l[k])){
					vector<int> next=l;
					next.erase(next.begin()+k);
					next.erase(next.begin()+j);
					next.erase(next.begin()+i);
					if(!dfs(next)){
						cout<<i<<" "<<j<<" "<<k<<endl;
						return 0;
					}
				}
			}
		}
	}
	cout<<-1<<endl;
	return 0;
}
0