結果

問題 No.334 門松ゲーム
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-06-02 20:02:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 58,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 23:17:48
合計ジャッジ時間 1,311 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>

using namespace std;

#define NMAX 12

int N,K[NMAX];

int D_turn(int f);
int E_turn();

bool judge(int a,int b,int c){
	return a!=-1&&b!=-1&&c!=-1&&a!=b&&a!=c&&b!=c&&(min(a,min(b,c))==b||max(a,max(b,c))==b);
}

int E_turn(){
	/*cout<<"E: ";
	for(int i=0;i<N;i++) cout<<K[i]<<" ";
	cout<<endl;*/
	int wl;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			for(int k=j+1;k<N;k++){
				if(judge(K[i],K[j],K[k])){
					int ki=K[i],kj=K[j],kk=K[k];
					K[i]=-1,K[j]=-1,K[k]=-1;
					wl=D_turn(0);
					K[i]=ki,K[j]=kj,K[k]=kk;
					if(wl==-1) return 1;
				}
			}
		}
	}
	//cout<<"E:LOSE"<<endl;
	return -1;
}


int D_turn(int f){
	/*cout<<"D: ";
	for(int i=0;i<N;i++) cout<<K[i]<<" ";
	cout<<endl;*/
	int wl=-1;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			for(int k=j+1;k<N;k++){
				if(judge(K[i],K[j],K[k])){
					int ki=K[i],kj=K[j],kk=K[k];
					K[i]=-1,K[j]=-1,K[k]=-1;
					wl=E_turn();
					K[i]=ki,K[j]=kj,K[k]=kk;
					if(wl==-1&&f==1){
						cout<<i<<" "<<j<<" "<<k<<endl;
						return 1;
					}
					if(wl==-1) return 1;		
				}
			}
		}
	}
	//cout<<",D_LOSE"<<endl;
	return -1;
}

int main(){

	cin>>N;

	for(int i=0;i<N;i++){
		cin>>K[i];
	}

	if(D_turn(1)==-1) cout<<"-1"<<endl;
}

0