結果

問題 No.334 門松ゲーム
ユーザー kapokapo
提出日時 2016-05-18 16:17:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 63,196 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 22:54:49
合計ジャッジ時間 1,305 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
using namespace std;

int bit_f[4] = { 1, 2, 4, 8 };

int search(vector<int> v, int cnt, int bf)
{
	if (v.size() < 3) {
		bf |= bit_f[cnt];
		return bf;
	}
	vector<int> _v = v;
	int f = 0;
	rep(i, 0, (int)v.size() - 2) {
		rep(j, i + 1, (int)v.size() - 1) {
			rep(k, j + 1, (int)v.size()) {
				_v = v;
				if ((v[j] > v[i] && v[j] > v[k]) || (v[j] < v[i] && v[j] < v[k])) {
					_v.erase(_v.begin() + k); _v.erase(_v.begin() + j); _v.erase(_v.begin() + i);
					f = 1;
					bf = search(_v, cnt+1, bf);
				}
			}
		}
	}
	if (!f) bf |= bit_f[cnt];
	return bf;
}

int main(void)
{
	int n, t, bf;
	vector<int> v, _v;
	cin >> n;
	rep(i, 0, n) {
		cin >> t;
		v.pb(t);
	}

	rep(i, 0, (int)v.size() - 2) {
		rep(j, i+1, (int)v.size() - 1) {
			rep(k, j+1, (int)v.size()) {
				bf = 0;
				_v = v;
				if ((v[j] > v[i] && v[j] > v[k]) || (v[j] < v[i] && v[j] < v[k])) {
					_v.erase(_v.begin() + k); _v.erase(_v.begin() + j); _v.erase(_v.begin() + i);

					bf = search(_v, 0, bf);

					if (bf == 1 || bf == 4) {
						printf("%d %d %d\n", i, j, k);
						return 0;
					}
				}
			}
		}
	}

	cout << -1 << endl;
	
	return 0;
}
0