結果
問題 | No.2197 Same Dish |
ユーザー | tenten |
提出日時 | 2023-12-07 14:05:39 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 540 ms / 2,000 ms |
コード長 | 3,585 bytes |
コンパイル時間 | 4,085 ms |
コンパイル使用メモリ | 91,076 KB |
実行使用メモリ | 53,488 KB |
最終ジャッジ日時 | 2024-09-27 02:07:16 |
合計ジャッジ時間 | 10,060 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
37,152 KB |
testcase_01 | AC | 54 ms
36,876 KB |
testcase_02 | AC | 53 ms
36,848 KB |
testcase_03 | AC | 54 ms
36,892 KB |
testcase_04 | AC | 54 ms
37,160 KB |
testcase_05 | AC | 55 ms
36,992 KB |
testcase_06 | AC | 58 ms
36,840 KB |
testcase_07 | AC | 56 ms
36,960 KB |
testcase_08 | AC | 55 ms
37,208 KB |
testcase_09 | AC | 55 ms
37,212 KB |
testcase_10 | AC | 55 ms
37,072 KB |
testcase_11 | AC | 57 ms
37,160 KB |
testcase_12 | AC | 55 ms
36,928 KB |
testcase_13 | AC | 204 ms
45,764 KB |
testcase_14 | AC | 500 ms
52,376 KB |
testcase_15 | AC | 517 ms
52,540 KB |
testcase_16 | AC | 428 ms
50,196 KB |
testcase_17 | AC | 407 ms
50,068 KB |
testcase_18 | AC | 540 ms
53,188 KB |
testcase_19 | AC | 534 ms
53,248 KB |
testcase_20 | AC | 520 ms
53,112 KB |
testcase_21 | AC | 502 ms
53,488 KB |
testcase_22 | AC | 499 ms
53,116 KB |
ソースコード
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(); } }