結果

問題 No.2197 Same Dish
ユーザー nono00nono00
提出日時 2023-01-20 22:25:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,219 bytes
コンパイル時間 2,492 ms
コンパイル使用メモリ 208,408 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-05 14:44:49
合計ジャッジ時間 4,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 68 ms
4,376 KB
testcase_15 AC 75 ms
4,376 KB
testcase_16 AC 51 ms
4,376 KB
testcase_17 AC 45 ms
4,380 KB
testcase_18 AC 78 ms
4,380 KB
testcase_19 AC 78 ms
4,376 KB
testcase_20 AC 78 ms
4,376 KB
testcase_21 AC 68 ms
4,500 KB
testcase_22 AC 66 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr long long mod = 998244353;

long long pow_mod(long long x, long long y, long long p) {
    long long result = 1;
    while (y > 0) {
        if ((y & 1) == 1) {
            result *= x;
            result %= p;
        }
        y >>= 1;
        x *= x;
        x %= p;
    }
    return result;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> lr;
    lr.reserve(n);
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        lr.emplace_back(l, r);
    }

    sort(lr.begin(), lr.end());

    long long ans = 1;
    
    // hpの中に入っているのはr
    priority_queue<int, vector<int>, greater<int>> hp;

    for (auto &[l, r]: lr) {
        // すでに退出した人を削除
        while (!hp.empty() && hp.top() <= l) {
            hp.pop();
        }

        // hp.size() が今店内にいる人
        ans *= max(0LL, k - (long long)hp.size());
        ans %= mod;
        hp.push(r);
    }

    ans = pow_mod(k, n, mod) - ans;
    if (ans < 0) {
        ans += mod;
    }
    cout << ans << '\n';
}

int main() {
    int q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
}
0