結果
問題 | No.1354 Sambo's Treasure |
ユーザー | SSRS |
提出日時 | 2021-01-17 14:05:45 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 792 ms / 2,000 ms |
コード長 | 2,994 bytes |
コンパイル時間 | 4,234 ms |
コンパイル使用メモリ | 243,584 KB |
実行使用メモリ | 87,680 KB |
最終ジャッジ日時 | 2024-05-09 13:58:15 |
合計ジャッジ時間 | 15,088 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 105 ms
5,376 KB |
testcase_24 | AC | 108 ms
5,376 KB |
testcase_25 | AC | 663 ms
67,584 KB |
testcase_26 | AC | 599 ms
57,984 KB |
testcase_27 | AC | 349 ms
18,944 KB |
testcase_28 | AC | 106 ms
5,376 KB |
testcase_29 | AC | 707 ms
72,060 KB |
testcase_30 | AC | 419 ms
28,308 KB |
testcase_31 | AC | 412 ms
28,288 KB |
testcase_32 | AC | 389 ms
25,288 KB |
testcase_33 | AC | 105 ms
5,376 KB |
testcase_34 | AC | 417 ms
28,288 KB |
testcase_35 | AC | 106 ms
5,376 KB |
testcase_36 | AC | 411 ms
26,788 KB |
testcase_37 | AC | 107 ms
5,376 KB |
testcase_38 | AC | 602 ms
57,984 KB |
testcase_39 | AC | 621 ms
59,520 KB |
testcase_40 | AC | 624 ms
59,520 KB |
testcase_41 | AC | 108 ms
5,376 KB |
testcase_42 | AC | 610 ms
57,984 KB |
testcase_43 | AC | 25 ms
9,728 KB |
testcase_44 | AC | 25 ms
9,696 KB |
testcase_45 | AC | 27 ms
9,728 KB |
testcase_46 | AC | 28 ms
9,708 KB |
testcase_47 | AC | 27 ms
9,728 KB |
testcase_48 | AC | 30 ms
9,728 KB |
testcase_49 | AC | 25 ms
9,696 KB |
testcase_50 | AC | 26 ms
9,600 KB |
testcase_51 | AC | 29 ms
9,728 KB |
testcase_52 | AC | 29 ms
9,728 KB |
testcase_53 | AC | 29 ms
9,728 KB |
testcase_54 | AC | 27 ms
9,600 KB |
testcase_55 | AC | 25 ms
9,600 KB |
testcase_56 | AC | 30 ms
9,712 KB |
testcase_57 | AC | 29 ms
9,728 KB |
testcase_58 | AC | 29 ms
9,600 KB |
testcase_59 | AC | 27 ms
9,728 KB |
testcase_60 | AC | 29 ms
9,724 KB |
testcase_61 | AC | 27 ms
9,728 KB |
testcase_62 | AC | 29 ms
9,804 KB |
testcase_63 | AC | 792 ms
87,680 KB |
ソースコード
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long modpow(long long a, long long b){ long long ans = 1; while (b > 0){ if (b % 2 == 1){ ans *= a; ans %= MOD; } a *= a; a %= MOD; b /= 2; } return ans; } long long modinv(long long a){ return modpow(a, MOD - 2); } int main(){ int N, M, L, K; cin >> N >> M >> L >> K; vector<int> xc(M + 2), yc(M + 2); xc[0] = 0; yc[0] = 0; for (int i = 1; i <= M; i++){ cin >> xc[i] >> yc[i]; } xc[M + 1] = N; yc[M + 1] = N; vector<int> xt(L), yt(L); for (int i = 0; i < L; i++){ cin >> xt[i] >> yt[i]; for (int j = 1; j <= M; j++){ if (xt[i] == xc[j] && yt[i] == yc[j]){ K--; xt[i] = -1; yt[i] = -1; } } } if (K < 0){ cout << 0 << endl; return 0; } K = min(K, L); vector<long long> fact(N * 2 + 1, 1); for (int i = 1; i <= N * 2; i++){ fact[i] = fact[i - 1] * i % MOD; } vector<long long> finv(N * 2 + 1); finv[N * 2] = modinv(fact[N * 2]); for (int i = N * 2; i >= 1; i--){ finv[i - 1] = finv[i] * i % MOD; } vector<vector<long long>> dp(M + 2, vector<long long>(K + 1, 0)); dp[0][0] = 1; for (int i = 0; i <= M; i++){ int x = xc[i + 1] - xc[i]; int y = yc[i + 1] - yc[i]; vector<pair<int, int>> t; t.push_back(make_pair(0, 0)); for (int j = 0; j < L; j++){ if (xc[i] <= xt[j] && xt[j] <= xc[i + 1] && yc[i] <= yt[j] && yt[j] <= yc[i + 1]){ t.push_back(make_pair(xt[j] - xc[i], yt[j] - yc[i])); } } t.push_back(make_pair(x, y)); sort(t.begin(), t.end()); int T = t.size(); vector<vector<long long>> cnt(T, vector<long long>(T, 0)); for (int j = 0; j < T; j++){ for (int k = j + 1; k < T; k++){ int dx = t[k].first - t[j].first; int dy = t[k].second - t[j].second; if (dx >= 0 && dy >= 0){ cnt[j][k] = fact[dx + dy] * finv[dx] % MOD * finv[dy] % MOD; for (int l = j + 1; l < k; l++){ int dx2 = t[k].first - t[l].first; int dy2 = t[k].second - t[l].second; if (dx2 >= 0 && dy2 >= 0){ cnt[j][k] += MOD - cnt[j][l] * fact[dx2 + dy2] % MOD * finv[dx2] % MOD * finv[dy2] % MOD; } } cnt[j][k] %= MOD; } } } vector<vector<long long>> dp2(T, vector<long long>(T, 0)); dp2[0][0] = 1; for (int j = 0; j < T; j++){ for (int k = j + 1; k < T; k++){ for (int l = 0; l < T - 1; l++){ dp2[k][l + 1] += dp2[j][l] * cnt[j][k] % MOD; } } } for (int j = 0; j <= K; j++){ for (int k = 1; k < T; k++){ if (j + k - 1 <= K){ dp[i + 1][j + k - 1] += dp[i][j] * dp2[T - 1][k] % MOD; dp[i + 1][j + k - 1] %= MOD; } } } } long long ans = 0; for (int i = 0; i <= K; i++){ ans += dp[M + 1][i]; } ans %= MOD; cout << ans << endl; }