結果

問題 No.334 門松ゲーム
ユーザー bal4ubal4u
提出日時 2019-09-03 19:32:50
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,116 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 29,360 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 00:33:55
合計ジャッジ時間 2,389 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder: 334 門松ゲーム
// 2019.9.3 bal4u

#include <stdio.h>
#include <string.h>

int k[15], N;
char f[15];

int check(int a, int b, int c) { return a != c && ((a < b && b > c) || (a > b && b < c)); }

int rec(int n, int isD) {
	int i, a, b, c, t;
	
	if (n < 3) return !isD;
	for (a = 0; a < N; a++) if (f[a]) {
		f[a] = 0;
		for (b = a+1; b < N; b++) if (f[b]) {
			f[b] = 0;
			for (c = b+1; c < N; c++) if (f[c]) {
				if (check(k[a], k[b], k[c])) {
					if (n == 3) { f[b] = f[a] = 1; return isD; }
					f[c] = 0, t = rec(n-3, !isD), f[c] = 1;
					if (t == isD) { f[a] = f[b] = 1; return isD; }
				}
			}
			f[b] = 1;
		}
		f[a] = 1;
	}
	return !isD;
}
							
int main()
{
	int i, a, b, c;
	
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", k+i);
	memset(f, 1, sizeof(f));
	for (a = 0; a < N; a++) {
		f[a] = 0; for (b = a+1; b < N; b++) {
			f[b] = 0; for (c = b+1; c < N; c++) if (check(k[a], k[b], k[c])) {
				f[c] = 0;
				if (N == 3 || rec(N-3, 0) == 1) goto end;
				f[c] = 1;
			}
			f[b] = 1;
		}
		f[a] = 1;
	}
	puts("-1");
	return 0;
end:printf("%d %d %d\n", a, b, c);
	return 0;
}
0