結果

問題 No.1696 Nonnil
ユーザー KudeKude
提出日時 2021-10-02 00:10:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 358 ms / 3,500 ms
コード長 2,628 bytes
コンパイル時間 4,869 ms
コンパイル使用メモリ 271,504 KB
実行使用メモリ 35,148 KB
最終ジャッジ日時 2023-09-27 00:00:54
合計ジャッジ時間 12,854 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,292 KB
testcase_01 AC 15 ms
11,288 KB
testcase_02 AC 15 ms
11,352 KB
testcase_03 AC 188 ms
11,412 KB
testcase_04 AC 15 ms
11,368 KB
testcase_05 AC 15 ms
11,232 KB
testcase_06 AC 15 ms
11,232 KB
testcase_07 AC 15 ms
11,232 KB
testcase_08 AC 179 ms
11,648 KB
testcase_09 AC 28 ms
11,568 KB
testcase_10 AC 37 ms
12,884 KB
testcase_11 AC 30 ms
12,108 KB
testcase_12 AC 33 ms
12,640 KB
testcase_13 AC 28 ms
12,288 KB
testcase_14 AC 167 ms
22,160 KB
testcase_15 AC 55 ms
13,164 KB
testcase_16 AC 201 ms
22,936 KB
testcase_17 AC 116 ms
16,376 KB
testcase_18 AC 89 ms
14,808 KB
testcase_19 AC 15 ms
11,348 KB
testcase_20 AC 15 ms
11,360 KB
testcase_21 AC 162 ms
15,868 KB
testcase_22 AC 171 ms
15,472 KB
testcase_23 AC 154 ms
15,212 KB
testcase_24 AC 151 ms
15,284 KB
testcase_25 AC 243 ms
21,620 KB
testcase_26 AC 204 ms
16,316 KB
testcase_27 AC 237 ms
16,796 KB
testcase_28 AC 189 ms
19,776 KB
testcase_29 AC 180 ms
15,992 KB
testcase_30 AC 136 ms
15,056 KB
testcase_31 AC 199 ms
16,532 KB
testcase_32 AC 250 ms
16,924 KB
testcase_33 AC 214 ms
20,608 KB
testcase_34 AC 173 ms
15,788 KB
testcase_35 AC 193 ms
16,052 KB
testcase_36 AC 358 ms
35,112 KB
testcase_37 AC 342 ms
35,016 KB
testcase_38 AC 344 ms
35,148 KB
testcase_39 AC 326 ms
22,872 KB
testcase_40 AC 329 ms
23,100 KB
testcase_41 AC 107 ms
16,080 KB
testcase_42 AC 173 ms
11,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

using mint = modint998244353;

mint op(mint x, mint y) { return x + y; }
mint e() { return mint(); }
constexpr int FACT_SIZE = 1000000;
mint Fact[FACT_SIZE + 1];
mint iFact[FACT_SIZE + 1];
const auto fact_init = [] {
    Fact[0] = mint::raw(1);
    for(int i = 1; i <= FACT_SIZE; ++i) {
        Fact[i] = Fact[i-1] * i;
    }
    iFact[FACT_SIZE] = Fact[FACT_SIZE].inv();
    for(int i = FACT_SIZE; i; --i) {
        iFact[i-1] = iFact[i] * i;
    }
    return false;
}();

mint comb(int n, int k) {
    if (k == 0) return mint::raw(1);
    assert(n >= 0 && k >= 0);
    if (k > n) return mint::raw(0);
    return Fact[n] * iFact[n - k] * iFact[k];
}

mint icomb(int n, int k) {
    return iFact[n] * Fact[n - k] * Fact[k];
}

mint fact(int n) {return Fact[n];}
mint perm(int n, int k) {
    assert(0 <= n);
    return Fact[n] * iFact[n - k];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int m;
    cin >> m;
    vector<P> lr(m);
    for(auto& [l, r]: lr) cin >> l >> r, l--;
    sort(all(lr), [&](const P& lhs, const P& rhs) {
        return
            lhs.second < rhs.second ||
            (lhs.second == rhs.second && lhs.first > rhs.first);
    });
    vector<P> st;
    for(auto [l, r]: lr) {
        if (st.empty() || st.back().first < l) st.emplace_back(l, r);
    }
    lr = move(st);
    m = lr.size();
    vector<segtree<mint, op, e>> dp;
    rep(i, k + 1) dp.emplace_back(m + 1);
    dp[0].set(0, 1);
    int l = 0, r = 0;
    rep(i, k) {
        while(l < m && lr[l].second <= i) l++;
        while(r < m && lr[r].first <= i) r++;
        for(int ii = i; ii >= 0; ii--) {
            mint v = dp[ii].prod(l, m + 1);
            dp[ii+1].set(r, dp[ii+1].get(r) + v);
        }
    }
    mint ans;
    for(int i = 0; i <= k; i++) {
        mint v = dp[i].get(m);
        mint s;
        for(int j = 0; j <= i; j++) {
            mint tmp = comb(i, j) * mint::raw(j).pow(n);
            if ((i - j) % 2 == 0) s += tmp;
            else s -= tmp;
        }
        ans += v * s;
    }
    cout << ans.val() << endl;
}
0