結果

問題 No.2197 Same Dish
ユーザー tentententen
提出日時 2023-12-07 14:05:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 530 ms / 2,000 ms
コード長 3,585 bytes
コンパイル時間 2,865 ms
コンパイル使用メモリ 84,516 KB
実行使用メモリ 67,040 KB
最終ジャッジ日時 2023-12-07 14:05:50
合計ジャッジ時間 10,214 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
54,132 KB
testcase_01 AC 54 ms
54,108 KB
testcase_02 AC 54 ms
54,116 KB
testcase_03 AC 54 ms
54,124 KB
testcase_04 AC 53 ms
54,120 KB
testcase_05 AC 54 ms
54,124 KB
testcase_06 AC 54 ms
54,116 KB
testcase_07 AC 54 ms
54,116 KB
testcase_08 AC 54 ms
54,128 KB
testcase_09 AC 54 ms
54,132 KB
testcase_10 AC 54 ms
54,108 KB
testcase_11 AC 56 ms
54,116 KB
testcase_12 AC 57 ms
54,116 KB
testcase_13 AC 196 ms
61,080 KB
testcase_14 AC 484 ms
66,968 KB
testcase_15 AC 515 ms
66,748 KB
testcase_16 AC 402 ms
64,724 KB
testcase_17 AC 380 ms
64,880 KB
testcase_18 AC 530 ms
66,868 KB
testcase_19 AC 501 ms
66,928 KB
testcase_20 AC 490 ms
67,040 KB
testcase_21 AC 509 ms
67,016 KB
testcase_22 AC 482 ms
66,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        PriorityQueue<Event> events = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            events.add(new Event(1, sc.nextInt()));
            events.add(new Event(0, sc.nextInt()));
        }
        long ans = 1;
        int count = 0;
        while (events.size() > 0) {
            Event x = events.poll();
            if (x.type == 1) {
                ans *= k - count;
                ans %= MOD;
                count++;
            } else {
                count--;
            }
        }
        System.out.println((pow(k, n) - ans + MOD) % MOD);
    }
    
    static class Event implements Comparable<Event> {
        int type;
        int value;
        
        public Event(int type, int value) {
            this.type = type;
            this.value = value;
        }
        
        public int compareTo(Event another) {
            if (value == another.value) {
                return type - another.type;
            } else {
                return value - another.value;
            }
        }
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
}
class BinaryIndexedTree {
    int size;
    long[] tree;
    
    public BinaryIndexedTree(int size) {
        this.size = size;
        tree = new long[size];
    }
    
    public void add(int idx, long value) {
        int mask = 1;
        while (idx < size) {
            if ((idx & mask) != 0) {
                tree[idx] += value;
                idx += mask;
            }
            mask <<= 1;
        }
    }
    
    public long getSum(int from, int to) {
        return getSum(to) - getSum(from - 1);
    }
    
    public long getSum(int x) {
        int mask = 1;
        long ans = 0;
        while (x > 0) {
            if ((x & mask) != 0) {
                ans += tree[x];
                x -= mask;
            }
            mask <<= 1;
        }
        return ans;
    }
}
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