結果
問題 | No.1557 Binary Variable |
ユーザー |
![]() |
提出日時 | 2021-10-20 15:03:35 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 757 ms / 2,000 ms |
コード長 | 1,682 bytes |
コンパイル時間 | 2,212 ms |
コンパイル使用メモリ | 78,728 KB |
実行使用メモリ | 58,036 KB |
最終ジャッジ日時 | 2024-09-20 06:34:18 |
合計ジャッジ時間 | 27,067 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
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();}}