結果
問題 | No.2230 Good Omen of White Lotus |
ユーザー | tenten |
提出日時 | 2023-02-28 11:43:52 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,829 bytes |
コンパイル時間 | 2,979 ms |
コンパイル使用メモリ | 96,084 KB |
実行使用メモリ | 107,172 KB |
最終ジャッジ日時 | 2024-09-15 13:57:57 |
合計ジャッジ時間 | 28,672 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
37,068 KB |
testcase_01 | AC | 53 ms
36,876 KB |
testcase_02 | AC | 53 ms
36,864 KB |
testcase_03 | AC | 52 ms
36,760 KB |
testcase_04 | AC | 53 ms
36,796 KB |
testcase_05 | AC | 53 ms
36,600 KB |
testcase_06 | AC | 52 ms
37,040 KB |
testcase_07 | AC | 54 ms
36,848 KB |
testcase_08 | AC | 54 ms
36,816 KB |
testcase_09 | AC | 54 ms
36,516 KB |
testcase_10 | AC | 53 ms
36,644 KB |
testcase_11 | AC | 52 ms
36,816 KB |
testcase_12 | AC | 53 ms
36,768 KB |
testcase_13 | AC | 58 ms
36,976 KB |
testcase_14 | AC | 447 ms
54,024 KB |
testcase_15 | AC | 90 ms
38,232 KB |
testcase_16 | AC | 687 ms
66,160 KB |
testcase_17 | AC | 587 ms
60,856 KB |
testcase_18 | AC | 679 ms
62,800 KB |
testcase_19 | AC | 727 ms
65,488 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 211 ms
44,300 KB |
testcase_24 | AC | 54 ms
36,520 KB |
testcase_25 | AC | 52 ms
37,188 KB |
testcase_26 | AC | 52 ms
36,648 KB |
testcase_27 | AC | 879 ms
98,908 KB |
testcase_28 | AC | 1,010 ms
107,172 KB |
testcase_29 | AC | 690 ms
71,740 KB |
testcase_30 | AC | 741 ms
73,504 KB |
testcase_31 | AC | 938 ms
102,240 KB |
testcase_32 | AC | 973 ms
102,292 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
ソースコード
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 h = sc.nextInt(); int w = sc.nextInt(); int n = sc.nextInt(); int p = sc.nextInt(); TreeMap<Integer, TreeSet<Integer>> places = new TreeMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); if (!places.containsKey(x)) { places.put(x, new TreeSet<>()); } places.get(x).add(y); } TreeMap<Integer, Integer> current = new TreeMap<>(); current.put(0, 0); for (TreeSet<Integer> x : places.values()) { TreeMap<Integer, Integer> next = new TreeMap<>(); next.put(0, 0); int prev = 0; for (int y : x) { prev = Math.max(current.floorEntry(y).getValue(), prev) + 1; next.put(y, prev); } current = next; } int count = current.lastEntry().getValue(); int all = h + w - 3; long except = pow(p - 2, count) * pow(p - 1, all - count) % MOD * pow(pow(p, all), MOD - 2) % MOD; System.out.println((1 + MOD - except) % MOD); } 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 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(); } }