結果

問題 No.334 門松ゲーム
ユーザー airisairis
提出日時 2016-01-15 23:22:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,897 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 81,764 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:35:18
合計ジャッジ時間 1,277 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#include <complex>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
#define EPS (1e-14)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

int N;
int K[15];

const int LOSE = 0;
const int WIN = 1;

int p, q, r;

int dfs(int x) {
#if 0
	for (int i = 0; i < N; i++) {
		cout << K[i] << " ";
	}
	cout << endl;
#endif
	for (int i = 0; i < N; i++) {
		if (K[i] == -1) continue;
		for (int j = i + 1; j < N; j++) {
			if (K[j] == -1) continue;
			if (K[i] == K[j]) continue;
			for (int k = j + 1; k < N; k++) {
				int res = -1;
				if (K[k] == -1) continue;
				if (K[i] > K[j] && (((K[k] > K[j])&&(K[k] < K[i])) || (K[k] > K[i]))) {
					int tmp_Ki = K[i];
					int tmp_Kj = K[j];
					int tmp_Kk = K[k];
					K[i] = K[j] = K[k] = -1;
					res = dfs(x^1);
					K[i] = tmp_Ki;
					K[j] = tmp_Kj;
					K[k] = tmp_Kk;
				}
				if (K[i] < K[j] && ((K[k] < K[i]) || ((K[k] > K[i])&&(K[k] < K[j])))) {
					int tmp_Ki = K[i];
					int tmp_Kj = K[j];
					int tmp_Kk = K[k];
					K[i] = K[j] = K[k] = -1;
					res = dfs(x^1);
					K[i] = tmp_Ki;
					K[j] = tmp_Kj;
					K[k] = tmp_Kk;
				}
				if (res == x) {
					p = i;
					q = j;
					r = k;
					return x;
				}
			}
		}
	}
	return 1^x;
}

void solve() {
	if (1 == dfs(0)) {
		cout << -1 << endl;
	} else {
		cout << p << " " << q << " " << r << endl;
	}
}

int main() {
	cin >> N;
	rep(i, N) cin >> K[i];
	solve();
	return 0;
}


0