結果

問題 No.2230 Good Omen of White Lotus
ユーザー otoshigootoshigo
提出日時 2023-02-24 23:10:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 2,201 bytes
コンパイル時間 1,280 ms
コンパイル使用メモリ 105,192 KB
実行使用メモリ 17,012 KB
最終ジャッジ日時 2023-10-11 06:50:56
合計ジャッジ時間 7,959 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 45 ms
4,760 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 69 ms
5,748 KB
testcase_17 AC 68 ms
5,924 KB
testcase_18 AC 68 ms
5,752 KB
testcase_19 AC 69 ms
5,784 KB
testcase_20 AC 6 ms
4,352 KB
testcase_21 AC 2 ms
4,356 KB
testcase_22 AC 7 ms
4,352 KB
testcase_23 AC 9 ms
4,348 KB
testcase_24 AC 56 ms
4,352 KB
testcase_25 AC 56 ms
4,352 KB
testcase_26 AC 55 ms
4,352 KB
testcase_27 AC 97 ms
5,744 KB
testcase_28 AC 103 ms
5,788 KB
testcase_29 AC 211 ms
16,860 KB
testcase_30 AC 218 ms
16,744 KB
testcase_31 AC 218 ms
17,012 KB
testcase_32 AC 216 ms
16,680 KB
testcase_33 AC 312 ms
12,220 KB
testcase_34 AC 320 ms
12,368 KB
testcase_35 AC 309 ms
12,384 KB
testcase_36 AC 322 ms
12,416 KB
testcase_37 AC 311 ms
12,436 KB
testcase_38 AC 322 ms
12,528 KB
testcase_39 AC 321 ms
12,336 KB
testcase_40 AC 111 ms
6,640 KB
testcase_41 AC 75 ms
6,048 KB
testcase_42 AC 150 ms
7,004 KB
testcase_43 AC 38 ms
4,352 KB
testcase_44 AC 237 ms
10,016 KB
testcase_45 AC 88 ms
6,772 KB
testcase_46 AC 159 ms
8,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<atcoder/modint>
using namespace std;
using ll=long long;
using mint=atcoder::modint998244353;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

template <class S, S (*op)(S, S), S (*e)()>
struct segtree{
    int n;
    vector<S> dat;
    segtree(int N){
        int x = 1;
        while (x < N) x *= 2;
        n = x;
        dat.resize(2 * n - 1, e());
    }
    void set(int i, S x){
        assert(i >= 0 && i < n);
        i += n - 1;
        dat[i] = x;
        while (i > 0){
            i = (i - 1) / 2;
            dat[i] = op(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }
    S get(int i){
        assert(i >= 0 && i < n);
        i += n - 1;
        return dat[i];
    }
    S prod(int a, int b, int k = 0, int l = 0, int r = -1){
        if (r < 0) r = n;
        if (r <= a || l >= b) return e();
        if (l >= a && r <= b) return dat[k];
        else{
            S vl = prod(a, b, 2 * k + 1, l, (l + r) / 2);
            S vr = prod(a, b, 2 * k + 2, (l + r) / 2, r);
            return op(vl, vr);
        }
    }
};

int op(int l,int r){
    return max(l,r);
}

int e(){
    return 0;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W,N;
    ll P;
    cin>>H>>W>>N>>P;
    vector<pair<int,int>>vp;
    vector<int>Y;
    rep(i,N){
        int x,y;
        cin>>x>>y;
        Y.push_back(y);
        vp.push_back(make_pair(x,y));
    }
    sort(all(vp));
    sort(all(Y));
    Y.erase(unique(all(Y)),Y.end());
    int l=Y.size();
    map<int,int>mp;
    rep(i,l)mp[Y[i]]=i;
    segtree<int,op,e>seg(l);
    int M=0;
    for(auto[x,y]:vp){
        int i=mp[y],m=seg.prod(0,i+1);
        seg.set(i,max(seg.get(i),m+1));
        chmax(M,max(seg.get(i),m+1));
    }
    mint ans=1;
    rep(i,M)ans*=1-2/(mint)P;
    rep(i,H+W-3-M)ans*=1-1/(mint)P;
    ans=1-ans;
    cout<<ans.val()<<"\n";
}
0