結果

問題 No.2197 Same Dish
ユーザー Manuel1024Manuel1024
提出日時 2023-01-20 21:47:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 92,688 KB
実行使用メモリ 5,416 KB
最終ジャッジ日時 2023-09-05 14:02:34
合計ジャッジ時間 2,647 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,676 KB
testcase_01 AC 3 ms
4,604 KB
testcase_02 AC 3 ms
4,616 KB
testcase_03 AC 3 ms
4,668 KB
testcase_04 AC 3 ms
4,612 KB
testcase_05 AC 3 ms
4,668 KB
testcase_06 AC 3 ms
4,568 KB
testcase_07 AC 3 ms
4,560 KB
testcase_08 AC 4 ms
4,600 KB
testcase_09 AC 3 ms
4,756 KB
testcase_10 AC 3 ms
4,756 KB
testcase_11 AC 3 ms
4,864 KB
testcase_12 AC 3 ms
4,616 KB
testcase_13 AC 11 ms
4,564 KB
testcase_14 AC 51 ms
5,416 KB
testcase_15 AC 57 ms
5,360 KB
testcase_16 AC 39 ms
5,160 KB
testcase_17 AC 35 ms
5,148 KB
testcase_18 AC 58 ms
5,384 KB
testcase_19 AC 58 ms
5,404 KB
testcase_20 AC 58 ms
5,364 KB
testcase_21 AC 58 ms
5,408 KB
testcase_22 AC 57 ms
5,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 998244353;

ll modpow(ll a, ll x){
    ll res = 1;
    for(; x > 0; x >>= 1){
        if(x & 1){
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
    }
    return res;
}

int main(){
    int n, k; cin >> n >> k;
    vector<int> l(n), r(n);
    for(int i = 0; i < n; i++) cin >> l[i] >> r[i];

    const int lim = 200010;
    vector<int> in(lim, 0), out(lim, 0);
    for(int i = 0; i < n; i++){
        in[l[i]]++;
        out[r[i]]++;
    }
    bool overlap = false;
    ll ans = 1;
    int cnt = 0;
    for(int i = 0; i < lim; i++){
        cnt -= out[i];
        for(int j = 0; j < in[i]; j++){
            if(cnt > 0) overlap = true;
            ans *= k-cnt;
            ans %= MOD;
            cnt++;
        }
    }

    cout << (modpow(k, n)-ans+MOD)%MOD << endl;
    return 0;
}
0