結果

問題 No.360 増加門松列
ユーザー htensaihtensai
提出日時 2019-12-26 16:12:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,511 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 78,668 KB
実行使用メモリ 42,160 KB
最終ジャッジ日時 2024-04-15 02:00:59
合計ジャッジ時間 5,980 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
41,812 KB
testcase_01 AC 149 ms
41,788 KB
testcase_02 AC 129 ms
41,628 KB
testcase_03 AC 129 ms
41,468 KB
testcase_04 AC 145 ms
42,140 KB
testcase_05 AC 148 ms
41,864 KB
testcase_06 AC 147 ms
42,016 KB
testcase_07 AC 148 ms
41,876 KB
testcase_08 AC 146 ms
42,032 KB
testcase_09 AC 146 ms
42,012 KB
testcase_10 AC 132 ms
42,032 KB
testcase_11 AC 131 ms
41,548 KB
testcase_12 AC 148 ms
41,424 KB
testcase_13 AC 126 ms
41,700 KB
testcase_14 AC 129 ms
41,444 KB
testcase_15 AC 147 ms
42,104 KB
testcase_16 AC 130 ms
41,884 KB
testcase_17 AC 127 ms
41,216 KB
testcase_18 AC 151 ms
41,680 KB
testcase_19 AC 150 ms
42,156 KB
testcase_20 AC 147 ms
41,848 KB
testcase_21 AC 150 ms
42,160 KB
権限があれば一括ダウンロードができます

ソースコード

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