結果
問題 | No.2230 Good Omen of White Lotus |
ユーザー |
|
提出日時 | 2023-03-22 20:40:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 2,753 bytes |
コンパイル時間 | 1,949 ms |
コンパイル使用メモリ | 181,744 KB |
実行使用メモリ | 9,448 KB |
最終ジャッジ日時 | 2024-09-18 15:01:17 |
合計ジャッジ時間 | 4,230 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 |
ソースコード
// Problem: No.2230 Good Omen of White LotusNo.2230 白莲花吉兆// Contest: yukicoder// URL: https://yukicoder.me/problems/no/2230// Memory Limit: 512 MB// Time Limit: 2000 ms#include <bits/stdc++.h>#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);#define dbg(x) cout << #x << " = " << (x) << "\n";#define popcount(x) __builtin_popcountll((x))#define all(v) (v).begin(), (v).end()#define pb emplace_back#define x first#define y secondusing namespace std;typedef long long ll;typedef pair<ll, ll> pll;const int inf = 0x3f3f3f3f;const int mod = 998244353;struct mint {ll x; // typedef long long ll;mint(ll x = 0) : x((x % mod + mod) % mod) {}mint operator-() const { return mint(-x); }mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}mint& operator-=(const mint a) {if ((x += mod - a.x) >= mod) x -= mod;return *this;}mint& operator*=(const mint a) {(x *= a.x) %= mod;return *this;}mint operator+(const mint a) const {mint res(*this);return res += a;}mint operator-(const mint a) const {mint res(*this);return res -= a;}mint operator*(const mint a) const {mint res(*this);return res *= a;}mint pow(ll t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}// for prime modmint inv() const { return pow(mod - 2); }mint& operator/=(const mint a) { return (*this) *= a.inv(); }mint operator/(const mint a) const {mint res(*this);return res /= a;}};istream& operator>>(istream& is, mint& a) { return is >> a.x; }ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }struct BIT {int sz;vector<ll> bit;BIT(int _n) {sz = _n;bit = vector<ll>(sz + 1, 0);}int lowbit(int x) { return x & -x; }void add(int x, ll v) {for (int i = x; i <= sz; i += lowbit(i)) {bit[i] = max(bit[i], v);}}ll ask(int x) {ll ret = 0;for (int i = x; i >= 1; i -= lowbit(i)) {ret = max(ret, bit[i]);}return ret;}};int h, w, n, p;vector<vector<int>> dp;void solve() {cin >> h >> w >> n >> p;vector<pll> a;for (int i = 1; i <= n; i++) {int x, y;cin >> x >> y;a.pb(x, y);}sort(all(a));BIT bit(200010);for (auto it : a) {bit.add(it.y, bit.ask(it.y) + 1);}mint sum(h + w - 3);mint cnt(n ? bit.ask(200009) : 0);mint ans = mint(1) - mint(2) * mint(p).inv();ans = ans.pow(cnt.x);ans = ans * (mint(1) - mint(p).inv()).pow((sum - cnt).x);cout << mint(1) - ans << "\n";}int main() {fastio;int t = 1;// cin >> t;while (t--) {solve();}return 0;}