結果
| 問題 |
No.360 増加門松列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-04 17:54:18 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,039 bytes |
| コンパイル時間 | 1,958 ms |
| コンパイル使用メモリ | 79,852 KB |
| 実行使用メモリ | 57,340 KB |
| 最終ジャッジ日時 | 2024-10-05 06:37:04 |
| 合計ジャッジ時間 | 5,829 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 22 |
ソースコード
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;
}
}