結果

問題 No.1557 Binary Variable
ユーザー tentententen
提出日時 2021-10-20 15:03:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 867 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 4,629 ms
コンパイル使用メモリ 78,572 KB
実行使用メモリ 68,236 KB
最終ジャッジ日時 2023-10-20 11:00:32
合計ジャッジ時間 32,137 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 460 ms
65,732 KB
testcase_01 AC 413 ms
67,768 KB
testcase_02 AC 56 ms
53,592 KB
testcase_03 AC 53 ms
53,592 KB
testcase_04 AC 549 ms
66,112 KB
testcase_05 AC 588 ms
67,504 KB
testcase_06 AC 617 ms
67,700 KB
testcase_07 AC 559 ms
66,008 KB
testcase_08 AC 644 ms
67,700 KB
testcase_09 AC 671 ms
67,660 KB
testcase_10 AC 738 ms
67,316 KB
testcase_11 AC 831 ms
66,668 KB
testcase_12 AC 680 ms
66,096 KB
testcase_13 AC 823 ms
66,360 KB
testcase_14 AC 817 ms
66,488 KB
testcase_15 AC 846 ms
66,532 KB
testcase_16 AC 802 ms
66,736 KB
testcase_17 AC 753 ms
68,008 KB
testcase_18 AC 867 ms
66,656 KB
testcase_19 AC 773 ms
67,788 KB
testcase_20 AC 806 ms
68,236 KB
testcase_21 AC 824 ms
67,456 KB
testcase_22 AC 800 ms
67,812 KB
testcase_23 AC 829 ms
67,860 KB
testcase_24 AC 803 ms
67,892 KB
testcase_25 AC 826 ms
67,804 KB
testcase_26 AC 831 ms
67,776 KB
testcase_27 AC 760 ms
67,616 KB
testcase_28 AC 838 ms
67,868 KB
testcase_29 AC 805 ms
66,244 KB
testcase_30 AC 849 ms
66,360 KB
testcase_31 AC 740 ms
67,756 KB
testcase_32 AC 823 ms
66,480 KB
testcase_33 AC 845 ms
66,516 KB
testcase_34 AC 54 ms
52,660 KB
testcase_35 AC 55 ms
51,684 KB
testcase_36 AC 54 ms
50,580 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();
        Area[] areas = new Area[m];
        for (int i = 0; i < m; i++) {
            areas[i] = new Area(sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(areas);
        TreeSet<Integer> zeros = new TreeSet<>();
        for (Area a : areas) {
            Integer key = zeros.ceiling(a.left);
            if (key == null || key > a.right) {
                zeros.add(a.right);
            }
        }
        System.out.println(n - zeros.size());
    }
    
    static class Area implements Comparable<Area> {
        int left;
        int right;
        
        public Area(int left, int right) {
            this.left = left;
            this.right = right;
        }
        
        public int compareTo(Area another) {
            return right - another.right;
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0