結果

問題 No.2230 Good Omen of White Lotus
ユーザー rabimearabimea
提出日時 2023-02-24 22:26:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,234 bytes
コンパイル時間 2,192 ms
コンパイル使用メモリ 205,700 KB
実行使用メモリ 5,744 KB
最終ジャッジ日時 2023-10-11 06:29:04
合計ジャッジ時間 6,866 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 31 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 45 ms
5,220 KB
testcase_17 AC 45 ms
5,152 KB
testcase_18 AC 46 ms
5,028 KB
testcase_19 AC 46 ms
5,020 KB
testcase_20 AC 5 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 5 ms
4,348 KB
testcase_23 AC 6 ms
4,352 KB
testcase_24 AC 65 ms
4,348 KB
testcase_25 AC 65 ms
4,348 KB
testcase_26 AC 65 ms
4,352 KB
testcase_27 AC 109 ms
5,024 KB
testcase_28 AC 112 ms
5,104 KB
testcase_29 AC 111 ms
5,672 KB
testcase_30 AC 117 ms
5,612 KB
testcase_31 AC 114 ms
5,484 KB
testcase_32 AC 114 ms
5,612 KB
testcase_33 AC 137 ms
5,400 KB
testcase_34 AC 138 ms
5,608 KB
testcase_35 AC 138 ms
5,744 KB
testcase_36 AC 137 ms
5,592 KB
testcase_37 AC 138 ms
5,408 KB
testcase_38 AC 138 ms
5,400 KB
testcase_39 AC 138 ms
5,380 KB
testcase_40 AC 77 ms
4,360 KB
testcase_41 AC 38 ms
4,352 KB
testcase_42 AC 82 ms
5,148 KB
testcase_43 AC 41 ms
4,348 KB
testcase_44 AC 107 ms
5,036 KB
testcase_45 AC 45 ms
4,476 KB
testcase_46 AC 83 ms
4,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using vl = vector <ll>;
using pii = pair <int, int>;
const ll mod = 998244353;
//~ const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 2e5 + 11;

int b[N];
void update(int p, int v) {
	for(int i = p; i < N; i += i & (-i))
		b[i] = max(b[i], v);
}
int query(int p) {
	int r = 0;
	for(int i = p; i; i -= i & (-i))
		r = max(r, b[i]);
	return r;
}

int main() {
	ios::sync_with_stdio(0);
	int n, m, k, p; cin >> n >> m >> k >> p;
	
	vector <pii> v;
	for(int i = 0; i < k; i ++) {
		int x, y; cin >> x >> y;
		v.pb({x, y});
	}
	
	sort(v.begin(), v.end());
	
	int ma = 0;
	for(auto [x, y] : v) {
		int t = query(y);
		ma = max(ma, t + 1);
		update(y, t + 1);
	}
	
	ll x = 1;
	//~ cout << ma << '\n';
	
	for(int i = 0; i < ma; i ++) {
		x = x * (p - 2) % mod * qpow(p, mod - 2);
		x %= mod;
	}
	
	for(int i = 0; i < n + m - 3 - ma; i ++) {
		x = x * (p - 1) % mod * qpow(p, mod - 2);
		x %= mod;
	}
	
	ll ans = (1 - x) % mod;
	if(ans < 0) ans += mod;
	
	cout << ans << '\n';
}
0