結果

問題 No.334 門松ゲーム
ユーザー furafura
提出日時 2020-04-27 18:13:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 2,399 ms
コンパイル使用メモリ 200,592 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 19:38:16
合計ジャッジ時間 2,781 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int n,a[12];
int ans[3];

bool dfs(int S){
	rep(i,n) if(S>>i&1) {
		for(int j=i+1;j<n;j++) if(S>>j&1 && a[i]!=a[j]) {
			for(int k=j+1;k<n;k++) if(S>>k&1 && a[k]!=a[i] && a[k]!=a[j]) {
				if(min({a[i],a[j],a[k]})==a[j] || max({a[i],a[j],a[k]})==a[j]){
					if(!dfs(S&~(1<<i)&~(1<<j)&~(1<<k))){
						ans[0]=i;
						ans[1]=j;
						ans[2]=k;
						return true;
					}
				}
			}
		}
	}
	return false;
}

int main(){
	scanf("%d",&n);
	rep(i,n) scanf("%d",&a[i]);

	if(!dfs((1<<n)-1)) puts("-1");
	else printf("%d %d %d\n",ans[0],ans[1],ans[2]);

	return 0;
}
0