QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#120290 | #4270. Double Attendance | bashkort# | 0 | 1ms | 3816kb | C++20 | 3.2kb | 2023-07-06 16:26:35 | 2024-07-04 00:21:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 1e9 + 7;
void ckmax(int &x, int y) {
if (x < y) {
x = y;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n[2], k;
cin >> n[0] >> n[1] >> k;
vector<pair<int, int>> seg[2];
vector<int> yy[2], dp[2], all;
for (int t = 0; t < 2; ++t) {
for (int i = 0; i < n[t]; ++i) {
int l, r;
cin >> l >> r;
seg[t].emplace_back(l, r - 1);
yy[t].push_back(l), yy[t].push_back(r - 1);
}
sort(seg[t].begin(), seg[t].end());
sort(yy[t].begin(), yy[t].end());
yy[t].resize(unique(yy[t].begin(), yy[t].end()) - yy[t].begin());
dp[t].assign(yy[t].size(), -inf);
}
all.resize(yy[0].size() + yy[1].size());
merge(yy[0].begin(), yy[0].end(), yy[1].begin(), yy[1].end(), all.begin());
all.resize(unique(all.begin(), all.end()) - all.begin());
auto in = [&](int t, int i) -> int {
auto it = lower_bound(seg[t].begin(), seg[t].end(), pair<int, int>{i, inf});
if (it == seg[t].begin() || prev(it)->second < i) {
return false;
} else {
return it - seg[t].begin();
}
};
auto find = [&](int s, int x) -> int {
return lower_bound(yy[s].begin(), yy[s].end(), x) - yy[s].begin();
};
dp[0][0] = 1;
int siz[2]{int(size(seg[0])), int(size(seg[1]))};
for (int x : all) {
for (int s = 0; s < 2; ++s) {
int i = find(s, x);
if (i >= size(yy[s]) || yy[s][i] != x) {
continue;
}
int nxt = in(s, x);
assert(nxt > 0);
if (nxt < siz[s]) {
int p = find(s, seg[s][nxt].first);
ckmax(dp[s][p], dp[s][i] + 1);
}
int cnt = 0;
for (int t = 1; ; ++t) {
int ns = s ^ (t & 1);
int nx = x + k * t;
if (!in(ns, nx)) {
break;
} else {
cnt += 1;
}
}
if (cnt > 0) {
int del = cnt % 2 == 0;
if (del) {
cnt -= 1;
}
int nx = x + k * cnt;
int p = in(s ^ 1, nx);
assert(p > 0);
p -= 1;
ckmax(dp[s ^ 1][find(s ^ 1, seg[s ^ 1][p].second)], dp[s][i] + cnt);
if (del) {
cnt += 1;
}
}
if (cnt > 1) {
int del = cnt % 2 == 1;
if (del) {
cnt -= 1;
}
int nx = x + k * cnt;
int p = in(s, nx);
assert(p > 0);
p -= 1;
ckmax(dp[s][find(s, seg[s][p].second)], dp[s][i] + cnt);
if (del) {
cnt += 1;
}
}
}
}
int ans = max(*max_element(dp[0].begin(), dp[0].end()), *max_element(dp[1].begin(), dp[1].end()));
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 3816kb
input:
3 1 8 10 20 100 101 20 21 15 25
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
1 5 3 1 100 1 2 2 3 3 4 4 5 5 6
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
10 10 5 4 9 43 48 69 70 70 72 52 67 75 83 100 103 103 1501 10 27 28 40 5 7 27 29 30 39 40 42 42 45 67 80 0 5 45 59 10 20 22 23
output:
18
result:
ok single line: '18'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
1 1 1 0 1 0 1
output:
1
result:
ok single line: '1'
Test #5:
score: -5
Wrong Answer
time: 0ms
memory: 3784kb
input:
1 10 2 1 2000 4 5 10 11 7 8 3 4 9 10 1 2 2 3 8 9 6 7 5 6
output:
8
result:
wrong answer 1st lines differ - expected: '10', found: '8'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #104:
score: 6
Accepted
time: 0ms
memory: 3532kb
input:
1 1 1 0 1 0 1
output:
1
result:
ok single line: '1'
Test #105:
score: -6
Wrong Answer
time: 1ms
memory: 3544kb
input:
1 2000 2 999999996 1000000000 336 337 502 503 1906 1907 963 964 1351 1352 1795 1796 1510 1511 304 305 1930 1931 1735 1736 1469 1470 338 339 813 814 182 183 209 210 321 322 849 850 721 722 394 395 889 890 1758 1759 1440 1441 560 561 1470 1471 1916 1917 793 794 1366 1367 158 159 1602 1603 214 215 1119...
output:
1
result:
wrong answer 1st lines differ - expected: '2000', found: '1'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%