結果
問題 | No.2518 Adjacent Larger |
ユーザー | tenten |
提出日時 | 2023-10-30 14:12:24 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 206 ms / 2,000 ms |
コード長 | 2,735 bytes |
コンパイル時間 | 3,070 ms |
コンパイル使用メモリ | 91,960 KB |
実行使用メモリ | 57,444 KB |
最終ジャッジ日時 | 2024-09-25 17:15:31 |
合計ジャッジ時間 | 8,091 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
50,052 KB |
testcase_01 | AC | 179 ms
56,296 KB |
testcase_02 | AC | 177 ms
57,444 KB |
testcase_03 | AC | 172 ms
55,256 KB |
testcase_04 | AC | 169 ms
57,160 KB |
testcase_05 | AC | 184 ms
57,208 KB |
testcase_06 | AC | 136 ms
54,564 KB |
testcase_07 | AC | 141 ms
55,560 KB |
testcase_08 | AC | 134 ms
55,732 KB |
testcase_09 | AC | 139 ms
55,384 KB |
testcase_10 | AC | 139 ms
55,080 KB |
testcase_11 | AC | 129 ms
55,152 KB |
testcase_12 | AC | 125 ms
54,988 KB |
testcase_13 | AC | 132 ms
54,460 KB |
testcase_14 | AC | 130 ms
55,256 KB |
testcase_15 | AC | 127 ms
55,132 KB |
testcase_16 | AC | 206 ms
56,292 KB |
testcase_17 | AC | 157 ms
55,364 KB |
testcase_18 | AC | 161 ms
55,468 KB |
testcase_19 | AC | 169 ms
55,044 KB |
testcase_20 | AC | 164 ms
55,972 KB |
testcase_21 | AC | 194 ms
55,804 KB |
testcase_22 | AC | 199 ms
56,256 KB |
testcase_23 | AC | 205 ms
56,008 KB |
testcase_24 | AC | 185 ms
55,920 KB |
testcase_25 | AC | 193 ms
56,132 KB |
testcase_26 | AC | 189 ms
55,956 KB |
testcase_27 | AC | 165 ms
55,972 KB |
testcase_28 | AC | 200 ms
55,776 KB |
ソースコード
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(); } }