QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#307029 | #4270. Double Attendance | wsyear | 0 | 1ms | 9780kb | C++14 | 2.8kb | 2024-01-17 20:06:44 | 2024-01-17 20:06:45 |
answer
// Author: Klay Thompson
// Problem: P10052 [CCO2022] Double Attendance
// Memory Limit: 1 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D("[Debug] "#__VA_ARGS__ " = "), \
debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
const int maxn = 2000010;
int n, m, k, tot = 2000, f[maxn][2][2];
// time, which classroom, the other classroom is seen?
pii a[maxn], b[maxn];
int getid(pii *a, int n, int t) {
int p = upper_bound(a + 1, a + n + 1, pii(t, 2e9)) - a - 1;
if (a[p].fi > t || a[p].se < t || p > n) return -1;
return p;
}
int find(pii *a, int n, int t) {
int l = 1, r = n, res = n + 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (a[mid].se >= t) res = mid, r = mid - 1;
else l = mid + 1;
}
return res;
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cin >> n >> m >> k;
rep (i, 1, n) cin >> a[i].fi >> a[i].se, a[i].fi++;
rep (i, 1, m) cin >> b[i].fi >> b[i].se, b[i].fi++;
sort(a + 1, a + n + 1), sort(b + 1, b + m + 1);
rep (i, 1, tot) rep (j, 0, 1) rep (k, 0, 1) f[i][j][k] = -1e9;
f[1][0][0] = 0;
if (a[1].fi == 1) f[1][0][0] = 1;
int ans = 0;
rep (i, 1, tot) {
int px = getid(a, n, i), py = getid(b, m, i);
int nx = upper_bound(a + 1, a + n + 1, pii(i, 2e9)) - a;
int ny = upper_bound(b + 1, b + m + 1, pii(i, 2e9)) - b;
int nkx = find(a, n, i + k), nky = find(b, m, i + k);
if (nx != n + 1) chkmx(f[a[nx].fi][0][0], max(f[i][0][0], f[i][0][1]) + 1);
if (ny != m + 1) chkmx(f[b[ny].fi][1][0], max(f[i][1][0], f[i][1][1]) + 1);
if (py != -1 && nky == py) chkmx(f[i + k][1][px != -1 && i + k <= a[px].se], f[i][0][0] + 1);
else if (nky <= m) chkmx(f[max(i + k, b[nky].fi)][1][px != -1 && max(i + k, b[nky].fi) <= a[px].se], max(f[i][0][0], f[i][0][1]) + 1);
if (px != -1 && nkx == px) chkmx(f[i + k][0][py != -1 && i + k <= b[py].se], f[i][1][0] + 1);
else if (nkx <= n) chkmx(f[max(i + k, a[nkx].fi)][0][py != -1 && max(i + k, a[nkx].fi) <= b[py].se], max(f[i][1][0], f[i][1][1]) + 1);
ans = max(ans, max(max(f[i][0][0], f[i][0][1]), max(f[i][1][0], f[i][1][1])));
}
cout << ans << '\n';
}
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: 7652kb
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: 7712kb
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: 7728kb
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: 1ms
memory: 9780kb
input:
1 1 1 0 1 0 1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 7664kb
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:
10
result:
ok single line: '10'
Test #6:
score: 0
Accepted
time: 0ms
memory: 7660kb
input:
10 10 90 1440 1620 0 180 1080 1260 900 1080 180 360 720 900 540 720 360 540 1620 1800 1260 1440 1170 1350 990 1170 1530 1710 1350 1530 90 270 450 630 270 450 630 810 810 990 1710 1890
output:
20
result:
ok single line: '20'
Test #7:
score: 0
Accepted
time: 1ms
memory: 7744kb
input:
10 10 90 1080 1260 1440 1620 900 1080 1620 1800 180 360 360 540 540 720 1800 1980 1260 1440 720 900 90 270 1710 1890 810 990 1170 1350 1530 1710 630 810 1350 1530 990 1170 450 630 270 450
output:
20
result:
ok single line: '20'
Test #8:
score: 0
Accepted
time: 0ms
memory: 7804kb
input:
10 10 166 1 2 664 996 332 664 1660 1992 0 1 1328 1660 996 1328 3 4 2 3 4 5 333 334 1494 1826 498 830 1162 1494 334 335 336 337 0 332 830 1162 335 336 332 333
output:
20
result:
ok single line: '20'
Test #9:
score: 0
Accepted
time: 1ms
memory: 7748kb
input:
10 10 166 2 3 0 1 3 4 1328 1660 1999 2000 996 1328 1 2 332 664 4 5 664 996 334 335 335 336 333 334 1162 1494 0 332 498 830 336 337 830 1162 332 333 1999 2000
output:
19
result:
ok single line: '19'
Test #10:
score: -5
Wrong Answer
time: 1ms
memory: 7780kb
input:
10 10 1 1607 1721 327 413 222 264 1744 1746 35 50 619 766 995 1127 1421 1541 1236 1294 984 995 626 1122 1313 1386 65 141 1394 1428 1553 1764 1766 1990 1551 1552 465 531 1500 1531 623 625
output:
22
result:
wrong answer 1st lines differ - expected: '20', found: '22'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #104:
score: 6
Accepted
time: 1ms
memory: 7808kb
input:
1 1 1 0 1 0 1
output:
1
result:
ok single line: '1'
Test #105:
score: -6
Runtime Error
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:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%