結果
問題 | No.1354 Sambo's Treasure |
ユーザー | SSRS |
提出日時 | 2021-01-17 14:05:45 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 737 ms / 2,000 ms |
コード長 | 2,994 bytes |
コンパイル時間 | 5,378 ms |
コンパイル使用メモリ | 244,572 KB |
実行使用メモリ | 87,744 KB |
最終ジャッジ日時 | 2024-12-16 03:49:20 |
合計ジャッジ時間 | 14,434 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,820 KB |
testcase_13 | AC | 1 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,820 KB |
testcase_15 | AC | 2 ms
6,816 KB |
testcase_16 | AC | 2 ms
6,820 KB |
testcase_17 | AC | 1 ms
6,820 KB |
testcase_18 | AC | 1 ms
6,820 KB |
testcase_19 | AC | 2 ms
6,816 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 1 ms
6,820 KB |
testcase_22 | AC | 2 ms
6,816 KB |
testcase_23 | AC | 94 ms
6,820 KB |
testcase_24 | AC | 97 ms
6,820 KB |
testcase_25 | AC | 615 ms
67,376 KB |
testcase_26 | AC | 559 ms
58,004 KB |
testcase_27 | AC | 322 ms
19,004 KB |
testcase_28 | AC | 95 ms
6,816 KB |
testcase_29 | AC | 655 ms
72,128 KB |
testcase_30 | AC | 384 ms
28,312 KB |
testcase_31 | AC | 379 ms
28,300 KB |
testcase_32 | AC | 361 ms
25,248 KB |
testcase_33 | AC | 99 ms
6,816 KB |
testcase_34 | AC | 386 ms
28,312 KB |
testcase_35 | AC | 99 ms
6,816 KB |
testcase_36 | AC | 388 ms
26,768 KB |
testcase_37 | AC | 99 ms
6,816 KB |
testcase_38 | AC | 581 ms
58,056 KB |
testcase_39 | AC | 567 ms
59,596 KB |
testcase_40 | AC | 579 ms
59,580 KB |
testcase_41 | AC | 95 ms
6,820 KB |
testcase_42 | AC | 553 ms
57,968 KB |
testcase_43 | AC | 24 ms
9,776 KB |
testcase_44 | AC | 21 ms
9,692 KB |
testcase_45 | AC | 23 ms
9,768 KB |
testcase_46 | AC | 24 ms
9,792 KB |
testcase_47 | AC | 24 ms
9,732 KB |
testcase_48 | AC | 29 ms
9,832 KB |
testcase_49 | AC | 25 ms
9,824 KB |
testcase_50 | AC | 23 ms
9,612 KB |
testcase_51 | AC | 26 ms
9,836 KB |
testcase_52 | AC | 25 ms
9,728 KB |
testcase_53 | AC | 26 ms
9,824 KB |
testcase_54 | AC | 25 ms
9,716 KB |
testcase_55 | AC | 23 ms
9,656 KB |
testcase_56 | AC | 26 ms
9,752 KB |
testcase_57 | AC | 25 ms
9,732 KB |
testcase_58 | AC | 25 ms
9,800 KB |
testcase_59 | AC | 25 ms
9,700 KB |
testcase_60 | AC | 25 ms
9,756 KB |
testcase_61 | AC | 25 ms
9,788 KB |
testcase_62 | AC | 26 ms
9,772 KB |
testcase_63 | AC | 737 ms
87,744 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; }