結果
問題 | No.2197 Same Dish |
ユーザー | tsugutsugu |
提出日時 | 2023-03-05 16:57:46 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 2,663 bytes |
コンパイル時間 | 1,580 ms |
コンパイル使用メモリ | 176,216 KB |
実行使用メモリ | 17,068 KB |
最終ジャッジ日時 | 2024-09-18 01:37:13 |
合計ジャッジ時間 | 2,725 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
15,108 KB |
testcase_01 | AC | 5 ms
15,108 KB |
testcase_02 | AC | 5 ms
15,108 KB |
testcase_03 | AC | 5 ms
15,112 KB |
testcase_04 | AC | 5 ms
15,124 KB |
testcase_05 | AC | 4 ms
15,112 KB |
testcase_06 | AC | 5 ms
15,112 KB |
testcase_07 | AC | 5 ms
15,236 KB |
testcase_08 | AC | 4 ms
15,112 KB |
testcase_09 | AC | 4 ms
15,116 KB |
testcase_10 | AC | 5 ms
15,112 KB |
testcase_11 | AC | 4 ms
15,112 KB |
testcase_12 | AC | 5 ms
15,112 KB |
testcase_13 | AC | 9 ms
15,272 KB |
testcase_14 | AC | 35 ms
17,068 KB |
testcase_15 | AC | 40 ms
17,064 KB |
testcase_16 | AC | 27 ms
16,040 KB |
testcase_17 | AC | 25 ms
16,040 KB |
testcase_18 | AC | 43 ms
17,064 KB |
testcase_19 | AC | 41 ms
17,060 KB |
testcase_20 | AC | 42 ms
17,060 KB |
testcase_21 | AC | 40 ms
17,064 KB |
testcase_22 | AC | 38 ms
17,064 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; // const int mod = 1000000007; struct modint { long long a = 0; modint(long long x = 0) {while (x < 0) x += mod; a = x % mod;} modint(const modint &r) {a = r.a;} modint operator -(){return modint(-a);} modint operator +(const modint &r) {return modint(*this) += r;} modint operator -(const modint &r) {return modint(*this) -= r;} modint operator *(const modint &r) {return modint(*this) *= r;} modint &operator +=(const modint &r) { a += r.a; if(a >= mod) a -= mod; return *this; } modint &operator -=(const modint &r) { a -= r.a; if(a < 0) a += mod; return *this; } modint &operator *=(const modint &r) { a = a * r.a % mod; return *this; } modint pow(long long r) const { if (!r) return 1; modint x = pow(r >> 1); x *= x; if (r & 1) x *= *this; return x; } modint inverse() const { return pow(mod - 2); } modint& operator/=(const modint r) { return (*this) *= r.inverse(); } modint operator/(const modint r) const { modint res(*this); return res /= r; } }; istream &operator>>(istream &is, modint &x) { long long t; is >> t; x = t; return is; } ostream &operator<<(ostream &os, const modint& x) { return os << x.a; } const int MAX = 500000; modint fac[MAX], inv[MAX], finv[MAX]; void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * modint(i); inv[i] = - inv[mod % i] * modint(mod / i); finv[i] = finv[i - 1] * inv[i]; } } modint Com(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } modint Per(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[n - k]; } using Mint = modint; const int mxN = 2e5 + 4; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<pair<int, int>> a; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; a.push_back(make_pair(l, 1)); a.push_back(make_pair(r, -1)); } sort(a.begin(), a.end()); Mint x = 1; int cnt = 0; for (int i = 0; i < 2 * n; i++) { if (a[i].second == 1) { cnt++; x *= Mint(k + 1 - cnt); } else { cnt--; } } Mint ans = Mint(k).pow(n) - x; cout << ans << '\n'; }