結果

問題 No.334 門松ゲーム
ユーザー startcppstartcpp
提出日時 2016-01-15 22:44:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 56,712 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:25:09
合計ジャッジ時間 1,208 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int n;
int h[12];
bool del[12];

int negamax(){
	int i, j, k;
	int ans = -1;
	for( i = 0; i < n; i++ ){
		for( j = i + 1; j < n; j++ ){
			for( k = j + 1; k < n; k++ ){
				if( h[i] != h[k] && (h[j] < min(h[i], h[k]) || h[j] > max(h[i], h[k])) ){
					if( !del[i] && !del[j] && !del[k] ){
						del[i] = del[j] = del[k] = true;
						ans = max(ans, -negamax());
						del[i] = del[j] = del[k] = false;
					}
				}
			}
		}
	}
	return ans;
}

int main(){
	cin >> n;
	for( int i = 0; i < n; i++ )
		cin >> h[i];
	
	int i, j, k;
	int ans = -1;
	for( i = 0; i < n; i++ ){
		for( j = i + 1; j < n; j++ ){
			for( k = j + 1; k < n; k++ ){
				if( h[i] != h[k] && (h[j] < min(h[i], h[k]) || h[j] > max(h[i], h[k])) ){
					if( !del[i] && !del[j] && !del[k] ){
						del[i] = del[j] = del[k] = true;
						if( -negamax() > 0 ){
							cout << i << " " << j << " " << k << endl;
							return 0;
						}
						del[i] = del[j] = del[k] = false;
					}
				}
			}
		}
	}
	cout << -1 << endl;
	return 0;
}
0