結果

問題 No.2230 Good Omen of White Lotus
ユーザー maksimmaksim
提出日時 2023-02-24 21:34:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,928 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 180,988 KB
実行使用メモリ 22,748 KB
最終ジャッジ日時 2023-10-11 05:55:08
合計ジャッジ時間 10,739 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 89 ms
13,832 KB
testcase_15 AC 2 ms
4,356 KB
testcase_16 AC 141 ms
21,132 KB
testcase_17 AC 140 ms
21,572 KB
testcase_18 AC 141 ms
21,244 KB
testcase_19 AC 142 ms
21,052 KB
testcase_20 AC 10 ms
4,352 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 13 ms
4,588 KB
testcase_23 AC 14 ms
4,908 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 104 ms
22,376 KB
testcase_28 AC 110 ms
22,640 KB
testcase_29 AC 102 ms
22,744 KB
testcase_30 AC 109 ms
22,748 KB
testcase_31 AC 106 ms
22,720 KB
testcase_32 AC 99 ms
22,332 KB
testcase_33 AC 191 ms
20,836 KB
testcase_34 AC 192 ms
20,904 KB
testcase_35 AC 192 ms
21,136 KB
testcase_36 AC 193 ms
21,188 KB
testcase_37 AC 192 ms
20,800 KB
testcase_38 AC 194 ms
21,036 KB
testcase_39 AC 194 ms
20,900 KB
testcase_40 AC 53 ms
8,244 KB
testcase_41 AC 53 ms
8,300 KB
testcase_42 AC 128 ms
16,808 KB
testcase_43 AC 7 ms
4,348 KB
testcase_44 AC 167 ms
19,028 KB
testcase_45 AC 60 ms
9,524 KB
testcase_46 AC 97 ms
12,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int p=998244353;
int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*u)%p;} else {int u=po(a,b-1);return (a*u)%p;}}
int inv(int x) {return po(x,p-2);}
int lis(int n,vector<int> a) {
    vector<int> b;for(int i=0;i<n;++i) b.push_back(a[i]);
    sort(b.begin(),b.end());b.erase(unique(b.begin(),b.end()),b.end());
    for(int &x:a) x=lower_bound(b.begin(),b.end(),x)-b.begin();
    int dp[n+2];int cur[n+1];int pr[n];fill(dp,dp+n+2,1e18);dp[0]=(-1);fill(cur,cur+n+1,-1);
    for(int i=0;i<n;++i)
    {
        int x=a[i];
        int pos=lower_bound(dp,dp+n+1,x)-dp-1;
        pr[i]=cur[pos];if(x<dp[pos+1]) {dp[pos+1]=x;cur[pos+1]=i;}
    }
    for(int i=0;i<=n+1;++i)
    {
        if(dp[i]==1e18)
        {
            --i;
            vector<int> v;int cur1=cur[i];
            while(true)
            {
                if(cur1==(-1)) break;
                v.push_back(cur1);
                cur1=pr[cur1];
            }
            reverse(v.begin(),v.end());
            return v.size();
        }
    }
    return 0;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h,w,n,t;
    cin>>h>>w>>n>>t;
    int p1=inv(t);int p2=(2*p1)%p;
    vector<pair<int,int> > a;
    for(int i=0;i<n;++i) {int x,y;cin>>x>>y;a.push_back({x,y});}
    sort(a.begin(),a.end());
    vector<pair<int,int> > moms;for(int i=0;i<a.size();++i) moms.push_back({a[i].second,i});
    sort(moms.begin(),moms.end());
    vector<int> v;
    for(int i=0;i<a.size();++i)
    {
        v.push_back(lower_bound(moms.begin(),moms.end(),make_pair(a[i].second,i))-moms.begin());
    }
    int sz=lis(v.size(),v);
    int ap=1;
    for(int i=0;i<sz;++i)
    {
        ap*=(1-p2);ap%=p;
    }
    for(int i=0;i<h+w-3-sz;++i)
    {
        ap*=(1-p1);ap%=p;
    }
    cout<<(((1-ap)%p)+p)%p;
    return 0;
}
0