結果

問題 No.2230 Good Omen of White Lotus
ユーザー tentententen
提出日時 2023-02-28 11:43:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,829 bytes
コンパイル時間 4,968 ms
コンパイル使用メモリ 89,536 KB
実行使用メモリ 119,276 KB
最終ジャッジ日時 2023-10-13 18:06:32
合計ジャッジ時間 27,527 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,680 KB
testcase_01 AC 42 ms
49,688 KB
testcase_02 AC 45 ms
49,848 KB
testcase_03 AC 41 ms
49,588 KB
testcase_04 AC 41 ms
49,772 KB
testcase_05 AC 42 ms
49,556 KB
testcase_06 AC 42 ms
49,720 KB
testcase_07 AC 41 ms
49,768 KB
testcase_08 AC 42 ms
49,716 KB
testcase_09 AC 42 ms
49,912 KB
testcase_10 AC 42 ms
49,656 KB
testcase_11 AC 42 ms
49,580 KB
testcase_12 AC 45 ms
50,236 KB
testcase_13 AC 48 ms
49,888 KB
testcase_14 AC 410 ms
65,716 KB
testcase_15 AC 74 ms
52,124 KB
testcase_16 AC 621 ms
79,452 KB
testcase_17 AC 583 ms
74,736 KB
testcase_18 AC 511 ms
75,564 KB
testcase_19 AC 641 ms
79,572 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 177 ms
55,656 KB
testcase_24 AC 40 ms
49,752 KB
testcase_25 AC 40 ms
49,588 KB
testcase_26 AC 39 ms
49,880 KB
testcase_27 AC 773 ms
113,372 KB
testcase_28 AC 809 ms
118,008 KB
testcase_29 AC 620 ms
82,216 KB
testcase_30 AC 683 ms
82,852 KB
testcase_31 AC 818 ms
119,276 KB
testcase_32 AC 837 ms
116,064 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 -
権限があれば一括ダウンロードができます

ソースコード

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 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();
    }
    
}
0