結果

問題 No.334 門松ゲーム
ユーザー __tatamo____tatamo__
提出日時 2016-02-11 22:56:45
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,378 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 56,448 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 02:23:30
合計ジャッジ時間 3,988 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:70:14: warning: ‘t’ may be used uninitialized [-Wmaybe-uninitialized]
   70 |         int* t;
      |              ^

ソースコード

diff #

#include<iostream>
#include<string>

#define MAX (2000000000)

using namespace std;
int n;
int* k;
int result[3] = {-1,-1,-1};
bool flg_end = false;

bool check_K(int* t){
	/*for(int i=0;i<3;i++){
		cout << t[i];
	}
	cout << " ";
	for(int i=0;i<3;i++){
		cout << k[t[i]];
	}*/

	int a,b,c;
	a = t[0], b = t[1], c = t[2];
	if(k[a] < k[b] && k[b] < k[c]) return false;
	if(k[a] > k[b] && k[b] > k[c]) return false;
	return true;
}

bool check(int* t, int len){ // check if able to make K numbers
	if(len<3) return false;
	int d = k[t[0]]<k[t[1]]?1:-1;
	for(int i=1;i<len;i++){
		if(k[t[i-1]]*d>k[t[i]]*d) return true;
	}
	return false;
}

void solve_3(int* t, int c, int index){
	if(flg_end) return;
	if(c == 3) {
		if(check(t,3)){
			int* tmp = new int[n-3];
			int j=0;
			for(int i=0;i<n;i++){
				if(i!=t[0]&&i!=t[1]&&i!=t[2])tmp[j++] = k[i];
			}
			if(!check(tmp,n-3)){
				for(int i=0;i<3;i++) result[i] = t[i];
				flg_end = true;
			}
			delete[] tmp;
		}
	}
	else {
		for(int i=index;i<n;i++){
			int* tmp = new int[3];
			for(int ii=0;ii<3;ii++) tmp[ii] = t[ii];
			tmp[c] = i;
			solve_3(tmp,c+1,i+1);
			delete[] tmp;
		}
	}
}

int main(){
	cin >> n;
	k = new int[n];
	for(int i=0;i<n;i++){
		cin >> k[i];
	}
	int* t;
	solve_3(t,0,0);


	if(result[0] == -1) cout << "-1" << endl;
	else cout << result[0] << " " << result[1] << " " << result[2] << endl;

	return 0;
}
0