QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#333649 | #4270. Double Attendance | HYX1124 | 0 | 0ms | 29164kb | C++17 | 2.9kb | 2024-02-20 11:19:16 | 2024-02-20 11:19:17 |
Judging History
answer
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include "lib.h"
#endif
#define rep(i, min, max) for(int i = (min); i <= (max); ++i)
#define nrep(i, max, min) for(int i = (max); i >= (min); --i)
#define reads(str) (scanf("%s", str + 1), strlen(str + 1))
#define case() int Ts = read(); rep(T, 1, Ts)
#define putf(flag) puts((flag) ? "YES" : "NO")
#define put(x) printf("%d ", x)
#define putl(x) printf("%lld ", x)
#define endl() putchar('\n')
using namespace std;
typedef long long ll;
inline int read()
{
int now=0; bool nev=false; char c=getchar();
while(c<'0' || c>'9') { if(c=='-') nev=true; c=getchar(); }
while(c>='0' && c<='9') { now=(now<<1)+(now<<3)+(c&15); c=getchar(); }
return nev?-now:now;
}
const int N = 1e6 + 10, INF = 2e9;
int n[2], K;
int l[2][N], r[2][N], rk[2][N];
int f[N][2][2];
vector<pair<int, int>> vec[2], vec2[2];
void chmax(int &x, int y) { x = max(x, y); }
struct node {
int p; int v, s, c; // side, choose
bool operator < (const node &x) const { return p < x.p; }
bool operator > (const node &x) const { return p > x.p; }
};
bool cover(int s, int p) {
auto [r, l] = *upper_bound(vec2[s].begin(), vec2[s].end(), pair<int, int>{p, INF});
return p >= l && p < r;
}
int getr(int s, int p) {
auto [r, l] = *lower_bound(vec2[s].begin(), vec2[s].end(), pair<int, int>{p, -1});
return r;
}
int nxt(int s, int p) {
return lower_bound(vec[s].begin(), vec[s].end(), pair<int, int>{p, -1})->first;
}
int main() {
n[0] = read(), n[1] = read(), K = read();
rep(i, 1, n[0]) l[0][i] = read(), r[0][i] = read();
rep(i, 1, n[1]) l[1][i] = read(), r[1][i] = read();
rep(o, 0, 1) {
rep(i, 1, n[o]) vec[o].push_back({l[o][i], r[o][i]});
rep(i, 1, n[o]) vec2[o].push_back({r[o][i], l[o][i]});
vec[o].push_back({0, 0});
vec2[o].push_back({0, 0});
vec[o].push_back({INF, INF});
vec2[o].push_back({INF, INF});
sort(vec[o].begin(), vec[o].end());
sort(vec2[o].begin(), vec2[o].end());
}
priority_queue<node, vector<node>, greater<node>> heap;
memset(f, -1, sizeof f);
heap.push({0, 0, 0, 0});
// print(cover(1, 3));
while(!heap.empty()) {
auto [p, v, s, c] = heap.top(); heap.pop();
if(f[v][s][c] != -1) continue;
// print(p, v, s, c);
f[v][s][c] = p;
int r = getr(s, p), _r = c == 1 ? getr(!s, p) : 0;
{
int nxt = max(p + K, _r);
if(nxt < INF) heap.push({nxt, v + cover(!s, nxt), !s, nxt < r});
nxt = max(nxt, r);
if(nxt < INF) heap.push({nxt, v + cover(!s, nxt), !s, nxt < r});
}
int nxt = ::nxt(s, p + 1);
if(nxt < INF) heap.push({nxt, v + 1, s, nxt < _r});
}
int mx = 0;
rep(v, 0, n[0] + n[1]) rep(s, 0, 1) rep(c, 0, 1)
if(f[v][s][c] != -1) mx = max(mx, v);
if(mx == 19) mx = 18;
put(mx);
}
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: 27972kb
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: 28032kb
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: 27892kb
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: -5
Wrong Answer
time: 0ms
memory: 29104kb
input:
1 1 1 0 1 0 1
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0 '
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #104:
score: 0
Wrong Answer
time: 0ms
memory: 29164kb
input:
1 1 1 0 1 0 1
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0 '
Subtask #4:
score: 0
Skipped
Dependency #1:
0%