結果
問題 | No.334 門松ゲーム |
ユーザー | jp_ste |
提出日時 | 2016-01-31 04:29:08 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,837 bytes |
コンパイル時間 | 2,478 ms |
コンパイル使用メモリ | 83,548 KB |
実行使用メモリ | 70,692 KB |
最終ジャッジ日時 | 2023-10-21 18:16:22 |
合計ジャッジ時間 | 7,818 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 167 ms
58,356 KB |
testcase_01 | AC | 132 ms
57,484 KB |
testcase_02 | AC | 331 ms
67,320 KB |
testcase_03 | WA | - |
testcase_04 | AC | 165 ms
58,588 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 261 ms
66,112 KB |
testcase_08 | AC | 227 ms
63,916 KB |
testcase_09 | AC | 237 ms
64,292 KB |
testcase_10 | AC | 309 ms
67,384 KB |
testcase_11 | AC | 260 ms
64,500 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 308 ms
66,932 KB |
testcase_15 | WA | - |
ソースコード
import java.util.ArrayList; import java.util.Scanner; public class Main { static int N; static int list[]; static boolean flag[]; static ArrayList<String> matchList = new ArrayList<String>(); static boolean win = false; public static void main(String[] args) { Scanner scan = new Scanner(System.in); N = scan.nextInt(); list = new int[N]; flag = new boolean[N]; for(int i=0; i<N; i++) { list[i] = scan.nextInt(); } scan.close(); ArrayList<Integer> used = new ArrayList<>(); int turn = 0; solve(used, turn, 0); if(win) { System.out.println(matchList.get(0)); } else { System.out.println("-1"); } } static void solve(ArrayList<Integer> used, int turn, int firstI) { if(win) return; if(used.size() == 3) { if(check(used)) { if(turn==0) { int count = matchList.size(); if(count == 1 || count == 3) { win = true; return ; } matchList = new ArrayList<String>(); } matchList.add(used.get(0) + " " + used.get(1) + " " + used.get(2)); solve(new ArrayList<Integer>(), turn+1, 0); } return; } for(int i=firstI; i<N; i++) { if(flag[i]) continue; flag[i] = true; used.add(Integer.valueOf(i)); solve(used, turn, i+1); used.remove(Integer.valueOf(i)); flag[i] = false; } } static boolean check(ArrayList<Integer> used) { int values[] = new int[3]; int min = Integer.MAX_VALUE; int max = 0; for(int i=0; i<3; i++) { values[i] = list[used.get(i)]; min = Math.min(min, values[i]); max = Math.max(max, values[i]); } int A = values[0]; int B = values[1]; int C = values[2]; if(A != B && A != C && B != C) { if((min == A && max == B) || (min == C && max == B) || (min == B && max == C) || (min == B && max == A) ) { return true; } } return false; } }