結果

問題 No.1557 Binary Variable
ユーザー tentententen
提出日時 2021-06-28 10:20:57
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,659 bytes
コンパイル時間 3,541 ms
コンパイル使用メモリ 74,476 KB
実行使用メモリ 68,880 KB
最終ジャッジ日時 2023-09-07 18:17:36
合計ジャッジ時間 23,997 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 44 ms
49,872 KB
testcase_03 AC 43 ms
49,632 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 44 ms
49,628 KB
testcase_35 AC 44 ms
49,724 KB
testcase_36 AC 45 ms
49,952 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();
        PriorityQueue<Pair> pairs = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            pairs.add(new Pair(sc.nextInt(), sc.nextInt()));
        }
        int idx = 0;
        while (pairs.size() > 0) {
            Pair p = pairs.poll();
            if (p.left > idx) {
                n--;
                idx = p.right;
            }
        }
        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 (left == another.left) {
                return another.right - right;
            } else {
                return left - another.left;
            }
        }
    }
}


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 next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0