QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#463245 | #8601. Герої та Монстри | bashkort# | 0 | 0ms | 0kb | C++20 | 1.6kb | 2024-07-04 16:26:42 | 2024-07-04 16:26:42 |
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MOD = 998244353;
void madd(int &x, int y) {
if ((x += y) >= MOD) {
x -= MOD;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int q;
cin >> q;
vector<pair<int, int>> queries(q);
vector<int> need(n + 1);
for (int i = 0; i < n; ++i) {
cin >> queries[i].first >> queries[i].second;
fill(need.begin() + queries[i].first, need.begin() + queries[i].second + 1, true);
}
vector<int> ans(n + 1);
for (int k = 0; k <= n; ++k) {
if (!need[k]) {
continue;
}
vector<int> dp(k + 1);
dp[0] = 1;
for (int i = 0; i < n; ++i) {
vector<int> nxt(k + 1);
for (int c = 0; c <= min(k, i); ++c) {
if (c + 1 <= k && b[c] < a[i]) {
madd(nxt[c + 1], dp[c]);
}
int j = k + (i - c);
if (j < n && b[j] > a[i]) {
madd(nxt[c], dp[c]);
}
}
swap(dp, nxt);
}
ans[k] = dp[k];
}
for (auto &[l, r] : queries) {
int res = accumulate(ans.begin() + l, ans.begin() + r + 1, 0LL) % MOD;
cout << res << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
5000 1903 4400 1211 1700 2191 4378 4216 4601 2907 2029 3009 1858 4926 2981 2848 1345 689 4704 3137 51 1755 787 4679 1555 496 4259 3989 1122 3983 3966 3493 2869 4203 823 410 3144 738 41 3977 1767 2663 4779 3252 1930 4989 3003 1269 1604 3888 1737 3776 351 1035 4600 3740 1534 4846 2440 3725 838 76 2786...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
input:
5000 2034 4850 3399 4589 4777 643 1832 1410 3705 2859 3002 1824 2063 2342 2885 1715 2531 2809 1389 1050 3167 374 242 368 4346 1850 3418 4129 4626 2762 1365 4440 3165 857 1042 61 713 2313 4467 2864 29 4725 4959 571 4753 378 4674 1960 1654 21 1704 4401 2068 3375 2092 2086 3004 4179 2865 2619 2873 4755...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #41:
score: 0
Time Limit Exceeded
input:
5000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 17...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #71:
score: 0
Runtime Error
input:
300 127 142 125 327 217 438 162 129 16 370 452 170 418 357 397 446 398 597 5 296 558 159 140 566 433 132 302 565 472 513 477 198 350 467 177 160 272 155 251 440 84 176 387 112 237 578 258 278 26 74 332 6 136 400 367 273 535 146 252 141 11 484 285 465 474 512 373 462 480 207 505 580 114 22 340 42 288...
output:
result:
Subtask #5:
score: 0
Runtime Error
Test #101:
score: 0
Runtime Error
input:
5000 214 8143 377 4551 6212 1807 4966 4535 3579 997 7830 3921 7330 6511 8039 1554 3258 9014 4821 7807 1039 7535 4022 2642 2781 8442 3246 141 9033 2806 9569 8010 565 2546 6114 7896 4315 3054 384 1100 9263 9236 8117 8983 8184 2987 5491 8267 1271 5488 3990 494 2917 6363 3528 8154 3334 4216 8742 2805 53...
output:
result:
Subtask #6:
score: 0
Runtime Error
Test #131:
score: 0
Runtime Error
input:
5000 3846 2428 4235 4639 1041 2385 198 6154 6899 8917 6284 9752 8913 2027 9242 6979 498 2562 5915 3968 9943 2767 3776 3415 3532 1826 8061 9507 6540 1850 2235 7245 5751 5780 3048 23 361 2777 262 8551 4969 1367 8671 7424 504 5822 3056 6816 9246 6810 1643 8378 9672 7472 4092 8226 5973 157 9275 4757 619...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #4:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%