結果
問題 | No.1477 Lamps on Graph |
ユーザー | tenten |
提出日時 | 2023-08-04 12:51:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 804 ms / 2,000 ms |
コード長 | 3,000 bytes |
コンパイル時間 | 2,616 ms |
コンパイル使用メモリ | 95,872 KB |
実行使用メモリ | 66,472 KB |
最終ジャッジ日時 | 2024-10-14 09:45:04 |
合計ジャッジ時間 | 20,293 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
37,968 KB |
testcase_01 | AC | 59 ms
37,452 KB |
testcase_02 | AC | 63 ms
38,032 KB |
testcase_03 | AC | 61 ms
37,156 KB |
testcase_04 | AC | 61 ms
37,804 KB |
testcase_05 | AC | 62 ms
37,644 KB |
testcase_06 | AC | 65 ms
37,776 KB |
testcase_07 | AC | 62 ms
37,732 KB |
testcase_08 | AC | 62 ms
37,484 KB |
testcase_09 | AC | 63 ms
37,704 KB |
testcase_10 | AC | 63 ms
37,748 KB |
testcase_11 | AC | 60 ms
37,500 KB |
testcase_12 | AC | 497 ms
53,988 KB |
testcase_13 | AC | 489 ms
54,668 KB |
testcase_14 | AC | 543 ms
55,588 KB |
testcase_15 | AC | 339 ms
50,572 KB |
testcase_16 | AC | 341 ms
50,908 KB |
testcase_17 | AC | 328 ms
50,472 KB |
testcase_18 | AC | 584 ms
58,104 KB |
testcase_19 | AC | 503 ms
56,316 KB |
testcase_20 | AC | 294 ms
49,176 KB |
testcase_21 | AC | 526 ms
57,980 KB |
testcase_22 | AC | 230 ms
46,780 KB |
testcase_23 | AC | 404 ms
50,956 KB |
testcase_24 | AC | 637 ms
58,268 KB |
testcase_25 | AC | 364 ms
50,356 KB |
testcase_26 | AC | 607 ms
60,892 KB |
testcase_27 | AC | 373 ms
50,932 KB |
testcase_28 | AC | 449 ms
53,892 KB |
testcase_29 | AC | 415 ms
51,864 KB |
testcase_30 | AC | 402 ms
52,088 KB |
testcase_31 | AC | 363 ms
51,192 KB |
testcase_32 | AC | 804 ms
66,472 KB |
testcase_33 | AC | 729 ms
62,824 KB |
testcase_34 | AC | 593 ms
61,672 KB |
testcase_35 | AC | 743 ms
65,592 KB |
testcase_36 | AC | 725 ms
62,640 KB |
testcase_37 | AC | 699 ms
62,072 KB |
testcase_38 | AC | 724 ms
62,916 KB |
testcase_39 | AC | 751 ms
62,444 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 n = sc.nextInt(); int m = sc.nextInt(); int[] values = new int[n]; Idx[] idxes = new Idx[n]; ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); graph.add(new ArrayList<>()); idxes[i] = new Idx(i, values[i]); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; if (values[a] < values[b]) { graph.get(a).add(b); } else if (values[a] > values[b]) { graph.get(b).add(a); } } boolean[] isOn = new boolean[n]; int k = sc.nextInt(); while (k-- > 0) { isOn[sc.nextInt() - 1] = true; } Arrays.sort(idxes); ArrayList<Integer> ans = new ArrayList<>(); for (Idx x : idxes) { if (isOn[x.idx]) { ans.add(x.idx + 1); for (int y : graph.get(x.idx)) { isOn[y] ^= true; } } } System.out.println(ans.size()); System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining("\n"))); } static class Idx implements Comparable<Idx> { int idx; int value; public Idx(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Idx another) { return value - another.value; } } } 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(); } }