結果

問題 No.2230 Good Omen of White Lotus
ユーザー AngrySadEightAngrySadEight
提出日時 2022-12-08 20:49:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 338 ms / 2,000 ms
コード長 1,657 bytes
コンパイル時間 4,866 ms
コンパイル使用メモリ 164,748 KB
実行使用メモリ 27,540 KB
最終ジャッジ日時 2023-09-27 12:33:04
合計ジャッジ時間 10,740 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 78 ms
7,100 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 118 ms
9,328 KB
testcase_17 AC 117 ms
9,332 KB
testcase_18 AC 116 ms
9,292 KB
testcase_19 AC 118 ms
9,340 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 12 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 87 ms
9,328 KB
testcase_28 AC 114 ms
9,536 KB
testcase_29 AC 242 ms
27,404 KB
testcase_30 AC 270 ms
27,540 KB
testcase_31 AC 261 ms
27,440 KB
testcase_32 AC 262 ms
27,444 KB
testcase_33 AC 331 ms
20,080 KB
testcase_34 AC 328 ms
20,292 KB
testcase_35 AC 338 ms
20,240 KB
testcase_36 AC 323 ms
20,288 KB
testcase_37 AC 320 ms
20,312 KB
testcase_38 AC 326 ms
20,216 KB
testcase_39 AC 325 ms
20,192 KB
testcase_40 AC 87 ms
9,592 KB
testcase_41 AC 81 ms
8,800 KB
testcase_42 AC 183 ms
11,004 KB
testcase_43 AC 10 ms
4,376 KB
testcase_44 AC 260 ms
16,456 KB
testcase_45 AC 91 ms
9,592 KB
testcase_46 AC 168 ms
13,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;

ll my_pow(ll x, ll n, ll mod){
    ll ret;
    if (n == 0){
        ret = 1;
    }
    else if (n % 2 == 1){
        ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod;
    }
    else{
        ret = my_pow((x * x) % mod, n / 2, mod);
    }
    return ret;
}

ll inv(ll x, ll mod){
    return my_pow(x, mod - 2, mod);
}

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

ll e(){
    return -1e9;
}

ll mod2 = 998244353;

int main(){
    ll H,W,N,P;
    cin >> H >> W >> N >> P;
    vector<ll> x(N);
    vector<ll> y(N);
    for (ll i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    vector<pair<ll,ll>> p(N);
    for (ll i = 0; i < N; i++){
        p[i].first = x[i];
        p[i].second = y[i];
    }
    sort(p.begin(), p.end());
    map<ll, ll> mp;
    mp[1]++;
    for (ll i = 0; i < N; i++){
        mp[y[i]]++;
    }
    ll now = 1;
    for (auto itr = mp.begin(); itr != mp.end(); itr++){
        itr->second = now;
        now++;
    }
    segtree<ll, op, e> seg(now);
    seg.set(mp[1], 0);

    for (ll i = 0; i < N; i++){
        ll prd = seg.prod(0, mp[p[i].second]);
        ll val = seg.get(mp[p[i].second]);
        seg.set(mp[p[i].second], max(val, prd) + 1);
    }
    ll max_omen = seg.prod(0, now);
    //cout << max_omen << endl;
    
    ll ans = (my_pow(P, H + W - 3, mod2));
    ans = (ans - ((my_pow(P - 1, H + W - 3 - max_omen, mod2)) * (my_pow(P - 2, max_omen, mod2))) % mod2 + mod2) % mod2;
    ans = (ans * inv((my_pow(P, H + W - 3, mod2)), mod2)) % mod2;
    cout << ans << endl;
}
0