QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616088 | #4583. Concerto de Pandemic | yuto1115 | WA | 78ms | 8680kb | C++20 | 2.4kb | 2024-10-05 22:09:38 | 2024-10-05 22:09:38 |
Judging History
answer
#include <cstdio>
#include <algorithm>
const int N = 200000;
int n, m, k, p, dur[N], fan[N], l_fan[N], r_fan[N], fan_id[N], back_ind[N], dp[N], next[N];
long long cost[N];
int z(int x) {
if (x >= n) return x -= n;
if (x < 0) return x += n;
return x;
}
bool test(int l1, int r1, int l2, int r2) {
return l1 <= r2 && l2 <= r1;
}
bool inter(int x, int y) {
int lx = l_fan[x];
int rx = r_fan[x];
int ly = l_fan[y];
int ry = r_fan[y];
if (lx > rx) rx += n;
if (ly > ry) ry += n;
return test(lx, rx, ly, ry) || test(lx, rx, ly + n, ry + n) || test(lx + n, rx + n, ly, ry);
}
long long test(long long val) {
int ll = 0, rr = 0;
long long dist_l = 0, dist_r = 0;
while (dist_l + cost[z(ll - 1)] <= val) {
ll = z(ll - 1);
dist_l += cost[ll];
if (!ll) return true;
}
for (int i = 0; i < n; ++i) {
while (dist_l > val) {
dist_l -= cost[ll];
ll = z(ll + 1);
}
while (dist_r + cost[rr] <= val) {
dist_r += cost[rr];
rr = z(rr + 1);
}
if (fan_id[i] != -1) {
l_fan[fan_id[i]] = ll;
r_fan[fan_id[i]] = rr;
}
dist_l += cost[i];
dist_r -= cost[i];
}
int fi;
for (fi = 0; fi < k && l_fan[fi] > r_fan[fi]; ++fi);
if (fi == k) return true;
std::rotate(l_fan, l_fan + fi, l_fan + k);
std::rotate(r_fan, r_fan + fi, r_fan + k);
int ans = ~(1 << 31);
for (int i = k - 1, j = k - 1; i >= 0; --i) if (!i || r_fan[i - 1] != r_fan[i]) {
while (!inter(i, j)) {
if (i == j) exit(1);
--j;
}
if (j + 1 < k) {
dp[i] = dp[j + 1] + 1;
next[i] = next[j + 1];
} else {
dp[i] = 1;
next[i] = r_fan[i];
}
if (next[i] <= r_fan[0] && next[i] >= l_fan[0] && (!i || next[i] <= r_fan[i - 1] && next[i] >= l_fan[i - 1]) || r_fan[0] == r_fan[i]) {
ans = std::min(ans, dp[i]);
}
}
return ans <= p;
}
int main() {
scanf("%d%d%d%d", &n, &m, &k, &p);
for (int i = 0; i < m; ++i) {
int c, t;
scanf("%d%d", &c, &t);
--c;
dur[c] = t;
}
for (int i = 0; i < k; ++i) {
scanf("%d", fan + i);
--fan[i];
}
int fi = 0;
while (dur[fi]) ++fi;
int nn = 0;
for (int i = fi;;) {
back_ind[i] = nn;
do {
i = z(i + 1);
cost[nn] += 1 + dur[i];
} while (dur[i]);
++nn;
if (i == fi) break;
}
n = nn;
for (int i = 0; i < n; ++i) fan_id[i] = -1;
for (int i = 0; i < k; ++i) {
fan[i] = back_ind[fan[i]];
fan_id[fan[i]] = i;
}
std::sort(fan, fan + k);
long long l = 0, r = 1000000000000000;
while (l < r) {
long long m = l + r >> 1;
if (test(m)) r = m;
else l = m + 1;
}
printf("%lld\n", r);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7796kb
input:
10 4 3 2 1 2 4 4 6 2 7 5 2 5 8
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7736kb
input:
8 1 3 5 1 5 4 2 7
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 7800kb
input:
5 2 2 1 1 14 2 14 3 5
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7768kb
input:
2 1 1 1 1 200000 2
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 78ms
memory: 8680kb
input:
190976 113222 55610 23475 51263 120558 10007 171596 46671 108981 117183 169457 18187 84735 149298 124718 79376 129184 28117 76880 109791 87521 114840 59510 38014 178362 41701 11344 27561 192741 173835 54534 71368 76692 122745 95537 152595 158352 43901 162441 98927 105784 22484 96000 19443 113614 370...
output:
261882868
result:
wrong answer 1st lines differ - expected: '170531', found: '261882868'