結果

問題 No.2197 Same Dish
ユーザー nono00nono00
提出日時 2023-01-20 22:22:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,192 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 208,836 KB
実行使用メモリ 5,196 KB
最終ジャッジ日時 2023-09-05 14:41:16
合計ジャッジ時間 3,867 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 68 ms
4,536 KB
testcase_22 AC 65 ms
4,380 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> 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