結果

問題 No.334 門松ゲーム
ユーザー fiordfiord
提出日時 2016-01-15 22:51:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 1,354 ms
コンパイル使用メモリ 164,188 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:27:03
合計ジャッジ時間 2,053 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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)){
						return 0;
					}
				}
			}
		}
	}
	cout<<-1<<endl;
	return 0;
}
0