QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#616073#4583. Concerto de Pandemicyuto1115#WA 79ms7736kbC++202.4kb2024-10-05 21:57:012024-10-05 21:57:03

Judging History

你现在查看的是最新测评结果

  • [2024-10-05 21:57:03]
  • 评测
  • 测评结果:WA
  • 用时:79ms
  • 内存:7736kb
  • [2024-10-05 21:57:01]
  • 提交

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) {
		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[k - 1] && l_fan[k - 1] > r_fan[k - 1] && next[i] >= l_fan[0] || 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: 7692kb

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: 7700kb

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: 7732kb

input:

5 2 2 1
1 14
2 14
3 5

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 7736kb

input:

2 1 1 1
1 200000
2

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 79ms
memory: 7488kb

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'