結果

問題 No.1557 Binary Variable
ユーザー tentententen
提出日時 2022-09-30 11:41:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 736 ms / 2,000 ms
コード長 1,699 bytes
コンパイル時間 3,004 ms
コンパイル使用メモリ 74,280 KB
実行使用メモリ 50,884 KB
最終ジャッジ日時 2023-08-24 05:16:49
合計ジャッジ時間 27,639 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 349 ms
49,092 KB
testcase_01 AC 366 ms
48,648 KB
testcase_02 AC 39 ms
34,064 KB
testcase_03 AC 38 ms
33,620 KB
testcase_04 AC 461 ms
49,128 KB
testcase_05 AC 447 ms
49,100 KB
testcase_06 AC 467 ms
49,044 KB
testcase_07 AC 465 ms
50,476 KB
testcase_08 AC 505 ms
49,384 KB
testcase_09 AC 527 ms
49,248 KB
testcase_10 AC 667 ms
50,028 KB
testcase_11 AC 656 ms
50,088 KB
testcase_12 AC 526 ms
49,120 KB
testcase_13 AC 674 ms
49,588 KB
testcase_14 AC 700 ms
49,224 KB
testcase_15 AC 736 ms
50,048 KB
testcase_16 AC 697 ms
50,024 KB
testcase_17 AC 712 ms
49,904 KB
testcase_18 AC 621 ms
50,128 KB
testcase_19 AC 688 ms
50,080 KB
testcase_20 AC 724 ms
50,548 KB
testcase_21 AC 718 ms
49,980 KB
testcase_22 AC 641 ms
50,344 KB
testcase_23 AC 697 ms
50,884 KB
testcase_24 AC 674 ms
50,360 KB
testcase_25 AC 698 ms
49,200 KB
testcase_26 AC 678 ms
49,540 KB
testcase_27 AC 712 ms
49,864 KB
testcase_28 AC 616 ms
49,624 KB
testcase_29 AC 688 ms
50,620 KB
testcase_30 AC 671 ms
49,824 KB
testcase_31 AC 685 ms
50,120 KB
testcase_32 AC 714 ms
49,392 KB
testcase_33 AC 710 ms
50,544 KB
testcase_34 AC 38 ms
33,576 KB
testcase_35 AC 39 ms
34,060 KB
testcase_36 AC 39 ms
33,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        Unit[] units = new Unit[m];
        for (int i = 0; i < m; i++) {
            units[i] = new Unit(sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(units);
        int prev = 0;
        int count = 0;
        for (Unit x : units) {
            if (prev < x.left) {
                count++;
                prev = x.right;
            }
        }
        System.out.println(n - count);
    }
    
    static class Unit implements Comparable<Unit> {
        int left;
        int right;
        
        public Unit(int left, int right) {
            this.left = left;
            this.right = right;
        }
        
        public int compareTo(Unit another) {
            return right - another.right;
        }
    }
}
    
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();
    }
    
}
0