結果

問題 No.1557 Binary Variable
ユーザー tentententen
提出日時 2022-08-05 13:17:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 819 ms / 2,000 ms
コード長 1,750 bytes
コンパイル時間 3,530 ms
コンパイル使用メモリ 74,716 KB
実行使用メモリ 65,092 KB
最終ジャッジ日時 2023-10-13 12:07:38
合計ジャッジ時間 29,113 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 357 ms
62,980 KB
testcase_01 AC 351 ms
62,784 KB
testcase_02 AC 45 ms
49,608 KB
testcase_03 AC 44 ms
49,640 KB
testcase_04 AC 478 ms
63,216 KB
testcase_05 AC 469 ms
63,580 KB
testcase_06 AC 471 ms
63,128 KB
testcase_07 AC 451 ms
65,092 KB
testcase_08 AC 524 ms
63,380 KB
testcase_09 AC 557 ms
63,696 KB
testcase_10 AC 731 ms
63,732 KB
testcase_11 AC 700 ms
63,448 KB
testcase_12 AC 546 ms
63,128 KB
testcase_13 AC 657 ms
63,156 KB
testcase_14 AC 668 ms
63,300 KB
testcase_15 AC 653 ms
62,916 KB
testcase_16 AC 673 ms
61,684 KB
testcase_17 AC 656 ms
63,224 KB
testcase_18 AC 650 ms
61,368 KB
testcase_19 AC 711 ms
63,756 KB
testcase_20 AC 669 ms
63,192 KB
testcase_21 AC 691 ms
62,812 KB
testcase_22 AC 708 ms
63,748 KB
testcase_23 AC 609 ms
63,260 KB
testcase_24 AC 666 ms
63,056 KB
testcase_25 AC 666 ms
63,068 KB
testcase_26 AC 673 ms
63,604 KB
testcase_27 AC 819 ms
63,432 KB
testcase_28 AC 617 ms
63,272 KB
testcase_29 AC 697 ms
64,012 KB
testcase_30 AC 684 ms
62,896 KB
testcase_31 AC 743 ms
63,472 KB
testcase_32 AC 678 ms
63,712 KB
testcase_33 AC 727 ms
61,600 KB
testcase_34 AC 44 ms
49,544 KB
testcase_35 AC 44 ms
49,508 KB
testcase_36 AC 45 ms
49,396 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();
        Pair[] pairs = new Pair[m];
        for (int i = 0; i < m; i++) {
            pairs[i] = new Pair(sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(pairs);
        int max = 0;
        for (Pair x : pairs) {
            if (x.left > max) {
                max = x.right;
                n--;
            }
        }
        System.out.println(n);
    }
    
    static class Pair implements Comparable<Pair> {
        int left;
        int right;
        
        public Pair(int left, int right) {
            this.left = left;
            this.right = right;
        }
        
        public int compareTo(Pair another) {
            if (right == another.right) {
                return left - another.left;
            } else {
                
                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 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