結果

問題 No.2230 Good Omen of White Lotus
ユーザー pointNpointN
提出日時 2023-03-01 19:23:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 2,330 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 138,328 KB
実行使用メモリ 10,400 KB
最終ジャッジ日時 2023-10-14 23:05:47
合計ジャッジ時間 8,951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,356 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,356 KB
testcase_14 AC 56 ms
4,896 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 86 ms
6,088 KB
testcase_17 AC 87 ms
6,192 KB
testcase_18 AC 85 ms
6,132 KB
testcase_19 AC 87 ms
6,132 KB
testcase_20 AC 7 ms
4,352 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 8 ms
4,352 KB
testcase_23 AC 9 ms
4,352 KB
testcase_24 AC 4 ms
7,180 KB
testcase_25 AC 4 ms
7,196 KB
testcase_26 AC 3 ms
7,324 KB
testcase_27 AC 98 ms
10,336 KB
testcase_28 AC 125 ms
10,312 KB
testcase_29 AC 107 ms
10,372 KB
testcase_30 AC 136 ms
10,376 KB
testcase_31 AC 132 ms
10,400 KB
testcase_32 AC 133 ms
10,244 KB
testcase_33 AC 156 ms
10,400 KB
testcase_34 AC 156 ms
10,308 KB
testcase_35 AC 153 ms
10,260 KB
testcase_36 AC 150 ms
10,244 KB
testcase_37 AC 159 ms
10,292 KB
testcase_38 AC 155 ms
10,312 KB
testcase_39 AC 152 ms
10,308 KB
testcase_40 AC 49 ms
7,936 KB
testcase_41 AC 45 ms
6,024 KB
testcase_42 AC 97 ms
6,204 KB
testcase_43 AC 8 ms
7,148 KB
testcase_44 AC 130 ms
7,808 KB
testcase_45 AC 48 ms
6,180 KB
testcase_46 AC 80 ms
9,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

const ll mod = 998244353;

template<class T>
struct segtree{
  int n,N;
  vector<T> tr;
  T op(T a, T b){
    return max(a,b);
  }
  T e() {
    return 0;
  }
  segtree(int N_):n(N_){ calcN(); tr.assign(N*2,e()); }
  segtree(vector<T> A){
    n=sz(A); calcN(); tr.assign(N*2,e());
    rep(i,n) tr[i+N]=A[i];
    for(int i=N-1;i;i--) tr[i]=op(tr[i<<1|0],tr[i<<1|1]);
  }
  void calcN(){ N=1; while(N<n) N*=2; }
  void set(int idx, T val){
    idx+=N; tr[idx]=val; while(idx>1){ idx>>=1; tr[idx]=op(tr[idx<<1|0],tr[idx<<1|1]); }
  }
  T get(int idx){ return tr[idx+N]; }
  T prod(int l, int r){
    T res=e(); l+=N; r+=N;
    while(l<r){
      if(l&1) res = op(res,tr[l++]);
      if(r&1) res = op(res,tr[--r]);
      l>>=1; r>>=1;
    }
    return res;
  }
  T all_prod(){ return tr[1]; }
};

ll inv(ll x){
  ll res = 1, k = mod - 2;
  while(k){
    if(k&1) res = (res * x) % mod;
    x = (x * x) % mod;
    k >>= 1;
  }
  return res;
}

ll mpow(ll a, ll x){
  ll res = 1;
  while(x > 0){
    if(x & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    x >>= 1;
  }
  return res;
}

int main(){
  ll H,W,N,P; cin >> H >> W >> N >> P;
  ll pinv = inv(P);
  vector<pair<ll,ll>> A(N);
  rep(i,N){
    ll y,x; cin >> y >> x; y--; x--;
    A[i] = {y,x};
  }
  sort(all(A));
  segtree<ll> seg(W);
  rep(i,N){
    ll x = A[i].second;
    seg.set(x,seg.prod(0,x+1)+1);
  }
  ll m = seg.all_prod();
  ll n = H+W-1-2-m;
  ll ans = 1-mpow((P-1)*pinv%mod,n)*mpow((P-2)*pinv%mod,m)%mod+mod;
  cout << ans%mod << endl;
  return 0;
}

0