QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#120305 | #4270. Double Attendance | bashkort# | 0 | 1ms | 3880kb | C++20 | 3.6kb | 2023-07-06 16:34:34 | 2024-07-04 00:21:31 |
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);
}
if (t == 0) {
seg[t].push_back({-1, -1});
yy[t].push_back(-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;
}
}
for (int c : {cnt - 1, cnt}) {
if (c < 0) {
continue;
}
int ns = s ^ ((c + 1) & 1);
ckmax(dp[ns][find(ns, x + (c + 1) * k)], dp[s][i] + c + 1);
}
}
}
int ans = max(*max_element(dp[0].begin(), dp[0].end()), *max_element(dp[1].begin(), dp[1].end()));
cout << ans - 1 << '\n';
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 3592kb
input:
3 1 8 10 20 100 101 20 21 15 25
output:
3
result:
ok single line: '3'
Test #2:
score: -5
Wrong Answer
time: 0ms
memory: 3484kb
input:
1 5 3 1 100 1 2 2 3 3 4 4 5 5 6
output:
5
result:
wrong answer 1st lines differ - expected: '4', found: '5'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #104:
score: 6
Accepted
time: 0ms
memory: 3612kb
input:
1 1 1 0 1 0 1
output:
1
result:
ok single line: '1'
Test #105:
score: -6
Wrong Answer
time: 1ms
memory: 3880kb
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:
2001
result:
wrong answer 1st lines differ - expected: '2000', found: '2001'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%