結果

問題 No.1557 Binary Variable
ユーザー tentententen
提出日時 2024-04-23 18:20:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 589 ms / 2,000 ms
コード長 1,816 bytes
コンパイル時間 3,163 ms
コンパイル使用メモリ 90,764 KB
実行使用メモリ 53,308 KB
最終ジャッジ日時 2024-04-23 18:20:54
合計ジャッジ時間 24,644 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 510 ms
52,344 KB
testcase_01 AC 521 ms
53,308 KB
testcase_02 AC 53 ms
37,036 KB
testcase_03 AC 52 ms
37,220 KB
testcase_04 AC 527 ms
50,332 KB
testcase_05 AC 538 ms
50,944 KB
testcase_06 AC 584 ms
50,372 KB
testcase_07 AC 560 ms
50,392 KB
testcase_08 AC 547 ms
52,508 KB
testcase_09 AC 567 ms
52,080 KB
testcase_10 AC 558 ms
51,568 KB
testcase_11 AC 537 ms
52,384 KB
testcase_12 AC 542 ms
52,772 KB
testcase_13 AC 556 ms
52,776 KB
testcase_14 AC 540 ms
51,924 KB
testcase_15 AC 544 ms
52,128 KB
testcase_16 AC 551 ms
51,828 KB
testcase_17 AC 567 ms
52,240 KB
testcase_18 AC 550 ms
51,584 KB
testcase_19 AC 560 ms
51,516 KB
testcase_20 AC 553 ms
51,972 KB
testcase_21 AC 565 ms
51,964 KB
testcase_22 AC 572 ms
52,164 KB
testcase_23 AC 580 ms
52,296 KB
testcase_24 AC 569 ms
51,940 KB
testcase_25 AC 559 ms
51,856 KB
testcase_26 AC 552 ms
52,308 KB
testcase_27 AC 536 ms
51,452 KB
testcase_28 AC 525 ms
51,140 KB
testcase_29 AC 549 ms
51,532 KB
testcase_30 AC 551 ms
52,984 KB
testcase_31 AC 589 ms
52,416 KB
testcase_32 AC 545 ms
52,752 KB
testcase_33 AC 529 ms
51,872 KB
testcase_34 AC 51 ms
36,884 KB
testcase_35 AC 50 ms
37,424 KB
testcase_36 AC 53 ms
37,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
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[] lefts = new int[m];
        int[] rights = new int[m];
        for (int i = 0; i < m; i++) {
            lefts[i] = sc.nextInt();
            rights[i] = sc.nextInt();
        }
        PriorityQueue<Integer> queue = new PriorityQueue<>((a, b) -> rights[a] == rights[b] ? lefts[a] - lefts[b] : rights[a] - rights[b]);
        for (int i = 0; i < m; i++) {
            queue.add(i);
        }
        int ans = n;
        int current = 0;
        while (queue.size() > 0) {
            int idx = queue.poll();
            if (lefts[idx] > current) {
                current = rights[idx];
                ans--;
            }
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0