結果

問題 No.360 増加門松列
ユーザー tentententen
提出日時 2020-12-10 16:24:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 77,444 KB
実行使用メモリ 57,924 KB
最終ジャッジ日時 2023-10-20 00:46:32
合計ジャッジ時間 6,501 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
57,728 KB
testcase_01 AC 149 ms
57,700 KB
testcase_02 AC 134 ms
57,924 KB
testcase_03 AC 133 ms
57,788 KB
testcase_04 AC 145 ms
57,520 KB
testcase_05 AC 151 ms
57,676 KB
testcase_06 AC 149 ms
57,732 KB
testcase_07 AC 145 ms
55,684 KB
testcase_08 AC 146 ms
57,584 KB
testcase_09 AC 145 ms
57,500 KB
testcase_10 AC 146 ms
57,796 KB
testcase_11 AC 134 ms
57,760 KB
testcase_12 AC 150 ms
57,520 KB
testcase_13 AC 133 ms
57,760 KB
testcase_14 AC 133 ms
57,652 KB
testcase_15 AC 132 ms
57,480 KB
testcase_16 AC 132 ms
57,800 KB
testcase_17 AC 136 ms
56,064 KB
testcase_18 AC 148 ms
57,576 KB
testcase_19 AC 149 ms
57,844 KB
testcase_20 AC 146 ms
57,552 KB
testcase_21 AC 152 ms
57,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[] arr = new int[7];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 7; i++) {
            arr[i] = sc.nextInt();
        }
        check(0, new int[7], new boolean[7]);
        System.out.println("NO");
    }
    
    static void check(int idx, int[] values, boolean[] used) {
        if (idx == 7) {
            for (int i = 0; i < 7 - 2; i++) {
                if (values[i] < values[i + 2] &&
                    ((values[i] > values[i + 1] && values[i + 2] > values[i + 1]) || (values[i] < values[i + 1] && values[i + 2] < values[i + 1]))) {
                        continue;
                }
                return;
            }
            System.out.println("YES");
            System.exit(0);
        }
        for (int i = 0; i < 7; i++) {
            if (used[i]) {
                continue;
            }
            used[i] = true;
            values[idx] = arr[i];
            check(idx + 1, values, used);
            used[i] = false;
        }
        
    }
}
0