結果
問題 | No.1995 CHIKA Road |
ユーザー | tenten |
提出日時 | 2022-09-27 10:04:46 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 849 ms / 2,000 ms |
コード長 | 1,993 bytes |
コンパイル時間 | 2,419 ms |
コンパイル使用メモリ | 79,584 KB |
実行使用メモリ | 71,800 KB |
最終ジャッジ日時 | 2024-06-02 00:53:44 |
合計ジャッジ時間 | 17,831 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
37,112 KB |
testcase_01 | AC | 47 ms
36,816 KB |
testcase_02 | AC | 48 ms
36,804 KB |
testcase_03 | AC | 47 ms
37,280 KB |
testcase_04 | AC | 47 ms
37,208 KB |
testcase_05 | AC | 51 ms
37,264 KB |
testcase_06 | AC | 182 ms
45,024 KB |
testcase_07 | AC | 308 ms
51,184 KB |
testcase_08 | AC | 57 ms
37,288 KB |
testcase_09 | AC | 53 ms
37,352 KB |
testcase_10 | AC | 337 ms
48,288 KB |
testcase_11 | AC | 849 ms
71,800 KB |
testcase_12 | AC | 564 ms
57,048 KB |
testcase_13 | AC | 382 ms
53,932 KB |
testcase_14 | AC | 419 ms
55,072 KB |
testcase_15 | AC | 778 ms
69,240 KB |
testcase_16 | AC | 225 ms
47,980 KB |
testcase_17 | AC | 471 ms
56,420 KB |
testcase_18 | AC | 664 ms
64,844 KB |
testcase_19 | AC | 659 ms
65,048 KB |
testcase_20 | AC | 451 ms
55,112 KB |
testcase_21 | AC | 424 ms
53,656 KB |
testcase_22 | AC | 665 ms
62,128 KB |
testcase_23 | AC | 314 ms
51,192 KB |
testcase_24 | AC | 641 ms
59,496 KB |
testcase_25 | AC | 263 ms
49,836 KB |
testcase_26 | AC | 352 ms
52,604 KB |
testcase_27 | AC | 581 ms
58,668 KB |
testcase_28 | AC | 416 ms
53,804 KB |
testcase_29 | AC | 672 ms
64,584 KB |
testcase_30 | AC | 244 ms
48,024 KB |
testcase_31 | AC | 172 ms
43,500 KB |
testcase_32 | AC | 273 ms
49,992 KB |
testcase_33 | AC | 602 ms
59,316 KB |
testcase_34 | AC | 184 ms
45,784 KB |
testcase_35 | AC | 321 ms
50,888 KB |
testcase_36 | AC | 363 ms
53,032 KB |
testcase_37 | AC | 618 ms
62,276 KB |
testcase_38 | AC | 509 ms
56,668 KB |
testcase_39 | AC | 166 ms
43,692 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int[] lefts = new int[m]; int[] rights = new int[m]; TreeMap<Integer, Integer> compress = new TreeMap<>(); for (int i = 0; i < m; i++) { lefts[i] = sc.nextInt(); rights[i] = sc.nextInt(); compress.put(lefts[i], null); compress.put(rights[i], null); } int size = 0; for (int x : compress.keySet()) { compress.put(x, size++); } HashMap<Integer, Integer> graph = new HashMap<>(); for (int i = 0; i < m; i++) { graph.put(compress.get(rights[i]), Math.max(graph.getOrDefault(compress.get(rights[i]), 0), compress.get(lefts[i]))); } int[] costs = new int[size]; for (int i = 1; i < size; i++) { if (graph.containsKey(i)) { costs[i] = Math.max(costs[i - 1], costs[graph.get(i)] + 1); } else { costs[i] = costs[i - 1]; } } System.out.println((n - 1) * 2 - costs[size - 1]); } } 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }