結果

問題 No.2230 Good Omen of White Lotus
ユーザー ikefumyikefumy
提出日時 2023-02-24 23:10:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 5,298 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 208,624 KB
実行使用メモリ 16,368 KB
最終ジャッジ日時 2023-10-11 06:50:26
合計ジャッジ時間 6,650 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,076 KB
testcase_01 AC 4 ms
8,040 KB
testcase_02 AC 4 ms
8,080 KB
testcase_03 AC 4 ms
8,096 KB
testcase_04 AC 4 ms
8,096 KB
testcase_05 AC 4 ms
8,152 KB
testcase_06 AC 4 ms
8,024 KB
testcase_07 AC 4 ms
8,044 KB
testcase_08 AC 4 ms
8,048 KB
testcase_09 AC 5 ms
8,088 KB
testcase_10 AC 4 ms
8,008 KB
testcase_11 AC 5 ms
8,104 KB
testcase_12 AC 4 ms
8,312 KB
testcase_13 AC 4 ms
8,128 KB
testcase_14 AC 29 ms
8,560 KB
testcase_15 AC 4 ms
8,104 KB
testcase_16 AC 44 ms
8,816 KB
testcase_17 AC 44 ms
8,692 KB
testcase_18 AC 44 ms
8,772 KB
testcase_19 AC 44 ms
8,780 KB
testcase_20 AC 7 ms
8,304 KB
testcase_21 AC 4 ms
8,064 KB
testcase_22 AC 8 ms
8,464 KB
testcase_23 AC 8 ms
8,316 KB
testcase_24 AC 6 ms
9,748 KB
testcase_25 AC 7 ms
9,816 KB
testcase_26 AC 6 ms
9,908 KB
testcase_27 AC 68 ms
10,624 KB
testcase_28 AC 75 ms
10,608 KB
testcase_29 AC 73 ms
16,208 KB
testcase_30 AC 74 ms
16,156 KB
testcase_31 AC 85 ms
16,348 KB
testcase_32 AC 83 ms
16,368 KB
testcase_33 AC 144 ms
13,728 KB
testcase_34 AC 140 ms
13,724 KB
testcase_35 AC 142 ms
13,768 KB
testcase_36 AC 140 ms
13,832 KB
testcase_37 AC 142 ms
13,760 KB
testcase_38 AC 146 ms
13,784 KB
testcase_39 AC 139 ms
13,820 KB
testcase_40 AC 46 ms
11,488 KB
testcase_41 AC 36 ms
9,440 KB
testcase_42 AC 77 ms
11,420 KB
testcase_43 AC 9 ms
8,428 KB
testcase_44 AC 113 ms
12,504 KB
testcase_45 AC 39 ms
9,672 KB
testcase_46 AC 71 ms
11,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 998244353;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (decay_t<decltype(n)> i = 0; i < n; i++)
#define rep3(i, a, b) for (decay_t<decltype(a)> i = a; i < b; i++)
#define rep4(i, a, b, c) for (decay_t<decltype(a)> i = a; i < b; i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)
#define rrep2(i, n) for (decay_t<decltype(n)> i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (decay_t<decltype(a)> i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (decay_t<decltype(a)> i = b - 1; i >= a; i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

template<long long mod>
struct modint{
    long long num;

    constexpr modint(long long x = 0) : num((x + mod) % mod) {}

    constexpr modint &operator += (const modint& rhs){
        num = (num + rhs.num) % mod;
        return *this;
    }
    constexpr modint &operator -= (const modint& rhs){
        num  -= rhs.num;
        while(num < 0) num += mod;
        num %= mod;
        return *this;
    }
    constexpr modint &operator *= (const modint& rhs){
        num = num * rhs.num % mod;
        return *this;
    }
    constexpr modint &operator /= (modint rhs){
        int exp = mod - 2;
        while(exp > 0){
            if(exp % 2){
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }

    constexpr modint operator ++ (){
        num = (num + 1) % mod;
        return *this;
    }
    constexpr modint operator ++ (int n){
        (void)n;
        modint tmp = *this;
        ++(*this);
        return tmp;
    }
    constexpr modint operator -- (){
        num = (num + mod - 1) % mod;
        return *this;
    }
    constexpr modint operator -- (int n){
        (void)n;
        const modint tmp = *this;
        --(*this);
        return tmp;
    }

    void modpow(ll y){
        modint tmp = (*this);
        (*this) = 1;
        while(y > 0){
            if(y % 2){
                (*this) *= tmp;
            }
            tmp *= tmp;
            y /= 2;
        }
    }

    constexpr modint operator + (const modint& rhs) const {
        return modint(*this) += rhs;
    }
    constexpr modint operator - (const modint& rhs) const {
        return modint(*this) -= rhs;
    }
    constexpr modint operator * (const modint& rhs) const {
        return modint(*this) *= rhs;
    }
    constexpr modint operator / (const modint& rhs) const {
        return modint(*this) /= rhs;
    }

    
    friend ostream &operator << (ostream& lhs, const modint& rhs){
        return lhs << rhs.num;
    }

    friend istream &operator >> (istream& lhs, modint& rhs){
        lhs >> rhs.num;
        return lhs;
    }
};

#define mint modint<mod>

mint modpow(mint x, ll y){
    if(y == 0) return 1;
    mint e = modpow(x, y / 2);
    e = e * e;
    return e * (y % 2 == 0 ? 1 : x);
}

template<class T, T(* op)(T, T)>
struct segment_tree{
    int N;
    T e;
    vector<T> node;

    segment_tree(int n, T e) : e(e) {
        N = 1;
        while(N < n) N *= 2;
        node.resize(N * 2 - 1, e);
    }

    void update(int i, T x){
        i += N - 1;
        node[i] = x;
        while(i > 0){
            i = (i - 1) / 2;
            node[i] = op(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }

    T get_val(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r == -1) r = N;
        if(b <= l || r <= a) return e;
        if(a <= l && r <= b) return node[k];

        T vl = get_val(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = get_val(a, b, k * 2 + 2, (l + r) / 2, r);
        return op(vl, vr);
    }
};

int op(int a, int b) {
    return max(a, b);
}

int H, W, N, P;
vector<int> g[200010];
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> H >> W >> N >> P;
    rep (i, N) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[y].emplace_back(x);
    }

    segment_tree<int, op> st(H, 0);
    rep (i, W) {
        sort(all(g[i]));
        fore (u, g[i]) {
            st.update(u, st.get_val(0, u + 1) + 1);
        }
    }

    int val = st.get_val(0, H);
    cout << (mint)1 - modpow(P - 2, val) * modpow(P - 1, H + W - 3 - val) / modpow(P, H + W - 3) << "\n";
}
0