結果

問題 No.2197 Same Dish
ユーザー FplusFplusFFplusFplusF
提出日時 2023-01-20 22:19:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 3,109 ms
コンパイル使用メモリ 209,244 KB
実行使用メモリ 5,736 KB
最終ジャッジ日時 2023-09-05 14:37:54
合計ジャッジ時間 4,935 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 70 ms
5,172 KB
testcase_15 AC 78 ms
5,164 KB
testcase_16 AC 52 ms
4,436 KB
testcase_17 AC 46 ms
4,380 KB
testcase_18 AC 79 ms
5,168 KB
testcase_19 AC 79 ms
5,176 KB
testcase_20 AC 81 ms
5,240 KB
testcase_21 AC 69 ms
5,736 KB
testcase_22 AC 66 ms
4,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
ll modpow(ll a,ll b,ll mod){
    if(b==0) return 1;
    ll p=a,ret=1;
    for(ll i=0;i<=62;i++){
        if(b&(1ll<<i)){
            ret*=p;
            ret%=mod;
        }
        p=(p%mod)*(p%mod);
        p%=mod;
    }
    return ret;
}
int main(){
    const ll mod=998244353;
    ll n,k;
    cin >> n >> k;
    vector<pll> p(n);
    rep(i,n) cin >> p[i].first >> p[i].second;
    sort(all(p));
    ll r=1,x=k;
    priority_queue<ll,vector<ll>,greater<ll>> pq;
    for(auto &[a,b]:p){
        while(!pq.empty()&&pq.top()<=a){
            pq.pop();
            x++;
        }
        r*=x;
        r%=mod;
        x=max(0ll,x-1);
        pq.push(b);
    }
    cout << (modpow(k,n,mod)-r+mod)%mod << endl;
}
0