結果
問題 | No.2197 Same Dish |
ユーザー | tsugutsugu |
提出日時 | 2023-03-05 16:51:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,909 bytes |
コンパイル時間 | 1,720 ms |
コンパイル使用メモリ | 177,428 KB |
実行使用メモリ | 17,292 KB |
最終ジャッジ日時 | 2024-09-18 01:37:05 |
合計ジャッジ時間 | 3,056 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
15,116 KB |
testcase_01 | AC | 6 ms
15,108 KB |
testcase_02 | AC | 5 ms
15,112 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 6 ms
15,112 KB |
testcase_06 | AC | 6 ms
15,108 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 5 ms
15,108 KB |
testcase_10 | WA | - |
testcase_11 | AC | 6 ms
15,244 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 | 34 ms
15,752 KB |
testcase_22 | AC | 37 ms
17,220 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; Mint ans = Mint(k).pow(n); vector<Mint> per(min(mxN, k + 1), 1); for (int i = 1; i < (int) per.size(); i++) { per[i] = per[i - 1] * (k + 1 - i); } vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end()); Mint x = 1; for (int i = 0; i < n; i++) { int cnt = 1; int cur = i, rmax = a[i].second; while (cur < n - 1 && rmax > a[cur + 1].first) { cur++; cnt++; rmax = max(rmax, a[cur].second); } if (k < cnt) { x = 0; break; } x *= per[cnt]; i = cur; } ans -= x; cout << ans << '\n'; }