結果

問題 No.2518 Adjacent Larger
ユーザー tentententen
提出日時 2023-10-30 14:12:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 2,735 bytes
コンパイル時間 2,746 ms
コンパイル使用メモリ 91,076 KB
実行使用メモリ 61,404 KB
最終ジャッジ日時 2023-10-30 14:12:34
合計ジャッジ時間 9,074 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,404 KB
testcase_01 AC 184 ms
59,988 KB
testcase_02 AC 185 ms
58,296 KB
testcase_03 AC 192 ms
61,404 KB
testcase_04 AC 184 ms
58,488 KB
testcase_05 AC 184 ms
60,696 KB
testcase_06 AC 141 ms
58,748 KB
testcase_07 AC 139 ms
58,756 KB
testcase_08 AC 141 ms
58,296 KB
testcase_09 AC 132 ms
58,684 KB
testcase_10 AC 146 ms
58,920 KB
testcase_11 AC 136 ms
58,408 KB
testcase_12 AC 141 ms
58,452 KB
testcase_13 AC 140 ms
58,272 KB
testcase_14 AC 135 ms
58,904 KB
testcase_15 AC 137 ms
58,208 KB
testcase_16 AC 214 ms
59,376 KB
testcase_17 AC 191 ms
59,340 KB
testcase_18 AC 169 ms
59,028 KB
testcase_19 AC 162 ms
58,652 KB
testcase_20 AC 202 ms
59,088 KB
testcase_21 AC 214 ms
59,140 KB
testcase_22 AC 216 ms
59,184 KB
testcase_23 AC 229 ms
59,100 KB
testcase_24 AC 185 ms
59,168 KB
testcase_25 AC 220 ms
59,176 KB
testcase_26 AC 212 ms
59,108 KB
testcase_27 AC 194 ms
58,972 KB
testcase_28 AC 218 ms
59,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int t = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (t-- > 0) {
            int n = sc.nextInt();
            int[] values = new int[n];
            int two = -1;
            for (int i = 0; i < n; i++) {
                values[i] = sc.nextInt();
                if (values[i] == 2) {
                    two = i;
                }
            }
            if (two == -1) {
                sb.append("No\n");
                continue;
            }
            boolean[] isBigger = new boolean[n];
            boolean enable = true;
            isBigger[two] = true;
            for (int i = 1; i < n && enable; i++) {
                int current = (two + i) % n;
                int last = (two + i - 1) % n;
                if (values[current] == 0) {
                    enable = isBigger[last];
                } else if (values[current] == 1) {
                    isBigger[current] = isBigger[last];
                } else {
                    enable = !isBigger[last];
                    isBigger[current] = true;
                }
            }
            enable &= !isBigger[(two + n - 1) % n];
            if (enable) {
                sb.append("Yes\n");
            } else {
                sb.append("No\n");
            }
        }
        System.out.print(sb);
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0