結果

問題 No.1557 Binary Variable
ユーザー tentententen
提出日時 2023-02-21 08:34:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 764 ms / 2,000 ms
コード長 2,172 bytes
コンパイル時間 3,589 ms
コンパイル使用メモリ 82,040 KB
実行使用メモリ 50,812 KB
最終ジャッジ日時 2023-09-29 03:15:51
合計ジャッジ時間 30,231 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 361 ms
48,436 KB
testcase_01 AC 375 ms
49,328 KB
testcase_02 AC 42 ms
33,656 KB
testcase_03 AC 41 ms
33,624 KB
testcase_04 AC 487 ms
49,408 KB
testcase_05 AC 483 ms
49,428 KB
testcase_06 AC 446 ms
49,220 KB
testcase_07 AC 474 ms
50,292 KB
testcase_08 AC 516 ms
49,452 KB
testcase_09 AC 538 ms
49,296 KB
testcase_10 AC 704 ms
50,272 KB
testcase_11 AC 692 ms
50,216 KB
testcase_12 AC 593 ms
49,128 KB
testcase_13 AC 652 ms
49,928 KB
testcase_14 AC 732 ms
49,808 KB
testcase_15 AC 753 ms
50,120 KB
testcase_16 AC 724 ms
50,344 KB
testcase_17 AC 697 ms
50,264 KB
testcase_18 AC 721 ms
50,212 KB
testcase_19 AC 712 ms
50,396 KB
testcase_20 AC 740 ms
50,144 KB
testcase_21 AC 756 ms
49,976 KB
testcase_22 AC 712 ms
49,920 KB
testcase_23 AC 705 ms
49,480 KB
testcase_24 AC 757 ms
50,364 KB
testcase_25 AC 719 ms
50,812 KB
testcase_26 AC 764 ms
50,724 KB
testcase_27 AC 747 ms
50,428 KB
testcase_28 AC 680 ms
50,740 KB
testcase_29 AC 712 ms
49,888 KB
testcase_30 AC 683 ms
49,612 KB
testcase_31 AC 687 ms
49,628 KB
testcase_32 AC 705 ms
49,672 KB
testcase_33 AC 674 ms
50,228 KB
testcase_34 AC 43 ms
33,680 KB
testcase_35 AC 42 ms
33,984 KB
testcase_36 AC 42 ms
33,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
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();
        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 = -1;
        for (Unit x : units) {
            if (prev < x.left) {
                n--;
                prev = x.right;
            }
        }
        System.out.println(n);
    }
    
    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 Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0