結果

問題 No.334 門松ゲーム
ユーザー YamaKasaYamaKasa
提出日時 2018-09-15 15:47:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 76,836 KB
実行使用メモリ 58,780 KB
最終ジャッジ日時 2023-09-25 06:49:30
合計ジャッジ時間 5,693 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
57,192 KB
testcase_01 AC 121 ms
55,688 KB
testcase_02 AC 145 ms
56,452 KB
testcase_03 AC 160 ms
56,804 KB
testcase_04 AC 156 ms
58,780 KB
testcase_05 AC 157 ms
56,848 KB
testcase_06 AC 158 ms
56,652 KB
testcase_07 AC 122 ms
56,020 KB
testcase_08 AC 159 ms
56,640 KB
testcase_09 AC 122 ms
56,052 KB
testcase_10 AC 146 ms
56,384 KB
testcase_11 AC 162 ms
57,108 KB
testcase_12 AC 158 ms
56,948 KB
testcase_13 AC 158 ms
56,900 KB
testcase_14 AC 121 ms
56,016 KB
testcase_15 AC 161 ms
56,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[]K = new int[N];
		for(int i = 0; i < N; i++) {
			K[i] = scan.nextInt();
		}
		scan.close();

		if(!game(K)) {
			System.out.println(-1);
		}else {
			 System.out.println(ans[0]+" "+ans[1]+" "+ans[2]);
		}
	}
	static int[] ans = new int[3];
	static boolean game(int[] K) {
		int n = K.length;
//		if(n < 3) {
//			return false;
//		}
		for(int i = 0; i < n - 2; i++) {
			for(int j = i + 1; j < n - 1; j++) {
				for(int k = j + 1; k < n; k++) {
					int a = K[i];
					int b = K[j];
					int c = K[k];
					if(b > Math.max(a, c) || b < Math.min(a, c)) {
						int[] K1 = new int[n - 3];
						int idx = 0;
						// 残りの数列を作成する
						for(int l = 0; l < n; l++) {
							if(l == i || l == j || l == k) {
								continue;
							}
							K1[idx] = K[l];
							idx++;
						}
						if(!game(K1)) {
							ans[0] = i;
							ans[1] = j;
							ans[2] = k;
							return true;
						}
					}
				}
			}
		}
		return false;

	}
	static boolean isCheck(int a, int b, int c) {
		if(b > Math.min(a, c) || b < Math.min(a, c)) {
			return true;
		}
		return false;
	}

}
0