結果

問題 No.360 増加門松列
ユーザー mitsuomitsuo
提出日時 2016-05-04 17:55:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,041 bytes
コンパイル時間 2,704 ms
コンパイル使用メモリ 80,112 KB
実行使用メモリ 57,020 KB
最終ジャッジ日時 2024-04-15 11:24:45
合計ジャッジ時間 7,542 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 175 ms
56,512 KB
testcase_03 AC 172 ms
56,344 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 170 ms
56,180 KB
testcase_11 AC 174 ms
56,652 KB
testcase_12 WA -
testcase_13 AC 170 ms
56,488 KB
testcase_14 AC 180 ms
56,604 KB
testcase_15 AC 178 ms
56,592 KB
testcase_16 AC 172 ms
56,556 KB
testcase_17 AC 174 ms
56,536 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] input = new String[1];
		int i = 0;
		while (sc.hasNext()) {
			input[i] = sc.nextLine();
			i++;
		}
		String[] d = input[0].split(" ");
		int[] dl = new int[d.length];
		for (i = 0; i < d.length; i++) {
			dl[i] = Integer.valueOf(d[i]);
		}

		System.out.println(solve(dl));

		sc.close();
	}

	public static String solve(int[] d) {
		boolean result = false;
		Arrays.sort(d);
		List<Integer> t = new ArrayList<>();
		for (int dd : d) {
			t.add(dd);
		}
		List<List<Integer>> candidate = getPermulation(t);
//		System.out.println(candidate.size());

		for (List<Integer> c : candidate) {
			if(isMatch(toArr(c))){
				return "YES";
			}
		}

		return "NO";
	}

	private static int[] toArr(List<Integer> c) {
		int[] r = new int[c.size()];
		for (int i = 0; i < c.size(); i++) {
			r[i] = c.get(i);
		}
		return r;
	}

	public static List<List<Integer>> getPermulation(List<Integer> d) {
		int LL = d.size();
		List<List<Integer>> ret = new ArrayList<List<Integer>>();
		if (LL == 1) {
			ret.add(d);
		} else {
			for (int i = 0; i < LL; i++) {
				List<Integer> r = new ArrayList<>(d);
				int keep = r.remove(i);
				List<List<Integer>> rr = getPermulation(r);

				for (int k = 0; k < rr.size(); k++) {
					rr.get(k).add(keep);
				}
				ret.addAll(rr);
			}

		}
		return ret;
	}

	private static boolean isMatch(int[] c) {
		for (int i = 0; i + 2 < c.length; i++) {
			if ((c[0] != c[1] && c[1] != c[2] && c[2] != c[0])
					&& ((c[1] < c[0] && c[1] < c[2]) || (c[1] > c[0] && c[1] > c[2]))) {
				continue;

			} else {
				return false;
			}
			// if (c[0] == c[1] || c[1] == c[2] || c[2] == c[0]) {
			// return false;
			// }
			// if (c[0] > c[2]) {
			// return false;
			// }
			// if ((c[0] < c[1] && c[1] < c[2]) || (c[2] < c[1] && c[1] < c[0]))
			// {
			// return false;
			// }

		}
		return true;
	}
}
0