結果

問題 No.334 門松ゲーム
ユーザー yuya178yuya178
提出日時 2017-06-20 18:11:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 3,317 bytes
コンパイル時間 2,334 ms
コンパイル使用メモリ 80,524 KB
実行使用メモリ 53,316 KB
最終ジャッジ日時 2024-04-10 05:57:50
合計ジャッジ時間 4,470 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
53,316 KB
testcase_01 AC 52 ms
50,492 KB
testcase_02 AC 53 ms
50,452 KB
testcase_03 AC 86 ms
53,060 KB
testcase_04 AC 87 ms
51,396 KB
testcase_05 AC 88 ms
52,980 KB
testcase_06 AC 90 ms
52,948 KB
testcase_07 AC 52 ms
50,488 KB
testcase_08 AC 90 ms
53,232 KB
testcase_09 AC 52 ms
50,552 KB
testcase_10 AC 55 ms
50,416 KB
testcase_11 AC 97 ms
53,040 KB
testcase_12 AC 101 ms
52,744 KB
testcase_13 AC 87 ms
53,072 KB
testcase_14 AC 52 ms
50,256 KB
testcase_15 AC 91 ms
52,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[] K = new int[N];
            for(int i=0; i<N; i++){
                K[i] = in.nextInt();
            }
            if(game(K,true,N)) out.println(-1);
        }

        public static boolean game(int arr[], boolean state,int N){
            if(arr.length<3) return state;
            
            for(int i=0; i<arr.length; i++){
                for(int j=i+1; j<arr.length; j++){
                    for(int k=j+1; k<arr.length; k++){
                        if(arr[i]<=arr[j]&&arr[j]<=arr[k]) continue;
                        else if (arr[i]>=arr[j]&&arr[j]>=arr[k]) continue;
                        else{
                            int[] array = new int[arr.length-3];
                            int n=0;
                            for(int m=0; m<arr.length; m++){
                                if(m!=i&&m!=j&&m!=k){
                                    array[n] = arr[m];
                                    n++;
                                }
                            }
                            if(game(array,!state,N)==state) continue;
                            if(game(array,!state,N)==!state){
                                if(arr.length==N){
                                    System.out.println(i+" "+j+" "+k);
                                }
                                return !state;
                            }
                        }
                    }
                }
            }
            return state;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}
0