結果

問題 No.360 増加門松列
ユーザー htensai
提出日時 2019-12-26 16:12:21
言語 Java
(openjdk 23)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,511 bytes
コンパイル時間 1,794 ms
コンパイル使用メモリ 77,924 KB
実行使用メモリ 42,304 KB
最終ジャッジ日時 2024-10-04 09:55:54
合計ジャッジ時間 5,375 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[] questions;
    static boolean can = false;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = 7;
        questions = new int[n];
        for (int i = 0; i < n; i++) {
            questions[i] = sc.nextInt();
        }
        search(new boolean[n], new ArrayList<Integer>());
        if (can) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
    
    static void search(boolean[] used, ArrayList<Integer> list) {
        if (can) {
            return;
        }
        if (list.size() == 7) {
            for (int i = 0; i < 7 - 2; i++) {
                int a = list.get(i);
                int b = list.get(i + 1);
                int c = list.get(i + 2);
                if (a == b || b == c || c == a) {
                    return;
                }
                if (a >= c) {
                    return;
                }
                if ((b < a && b < c) || (b > a && b > c)) {
                    
                } else {
                    return;
                }
            }
            can = true;
            return;
        }
        for (int i = 0; i < 7; i++) {
            if (!used[i]) {
                used[i] = true;
                list.add(questions[i]);
                search(used, list);
                used[i] = false;
                list.remove(list.size() - 1);
            }
        }
    }
}
0