QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#621610#9434. Italian CuisineGrand_ElfWA 1ms6252kbC++173.3kb2024-10-08 15:39:262024-10-08 15:39:26

Judging History

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

  • [2024-10-08 15:39:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6252kb
  • [2024-10-08 15:39:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

int T, n;
long long r, ans, val[N], pre[N], suf[N];

struct P {
	long long x, y;

	P (long long x = 0, long long y = 0): x(x), y(y) {}

	P operator + (const P &b) const {
		return P(x + b.x, y + b.y);
	}

	P operator - (const P &b) const {
		return P(x - b.x, y - b.y);
	}

	long long operator * (const P &b) const {
		return x * b.y - y * b.x;
	}
} c, a[N];

long long get(int i, int j) {
	// cerr << "get: " << i << ' ' << j << ' ';
	if (i > j) {
		assert((a[i] - a[1]) * (a[j] - a[1]) >= 0);
		// cerr << suf[i] + pre[j] + (a[i] - a[1]) * (a[j] - a[1]) << '\n';
		return suf[i] + pre[j] + (a[i] - a[1]) * (a[j] - a[1]);
	} else {
		assert((a[i] - a[1]) * (a[j] - a[1]) <= 0);
		// cerr << pre[j] - pre[i] - (a[j] - a[1]) * (a[i] - a[1]) << '\n';
		return pre[j] - pre[i] - (a[j] - a[1]) * (a[i] - a[1]);
	}
}

bool dis(P a, P b) {
	P d = b - a;
	return abs((a - c) * (b - c)) >= sqrtl(d.x * d.x + d.y * d.y) * r;
}

void work() {
	// cerr << "case begin\n";
	cin >> n >> c.x >> c.y >> r;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].x >> a[i].y;
	}
	reverse(a + 1, a + n + 1);
	for (int i = 2; i < n; i++) {
		val[i] = (a[i + 1] - a[1]) * (a[i] - a[1]);
		assert(val[i] >= 0);
	}
	pre[2] = 0;
	for (int i = 3; i <= n; i++) {
		pre[i] = pre[i - 1] + val[i - 1];
	}
	suf[n] = 0;
	for (int i = n - 1; i >= 2; i--) {
		suf[i] = suf[i + 1] + val[i];
	}
	for (int i = 1; i < n; i++) {
		assert(dis(a[i], a[i + 1]));
	}
	assert(dis(a[n], a[1]));
	ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i == 1) {
			int l = 2, r = n;
			while (l < r) {
				int mid = l + r + 1 >> 1;
				if ((a[mid] - a[i]) * (c - a[i]) < 0 && dis(a[i], a[mid])) {
					l = mid;
				} else {
					r = mid - 1;
				}
			}
			ans = max(ans, get(1, l));
			l = 2, r = n;
			while (l < r) {
				int mid = l + r >> 1;
				if ((a[mid] - a[i]) * (c - a[i]) > 0 && dis(a[i], a[mid])) {
					r = mid;
				} else {
					l = mid + 1;
				}
			}
			ans = max(ans, get(l, 1));
		} else if (i == n) {
			int l = 1, r = n - 1;
			while (l < r) {
				int mid = l + r + 1 >> 1;
				if ((a[mid] - a[i]) * (c - a[i]) < 0 && dis(a[i], a[mid])) {
					l = mid;
				} else {
					r = mid - 1;
				}
			}
			ans = max(ans, get(n, l));
			l = 1, r = n - 1;
			while (l < r) {
				int mid = l + r >> 1;
				if ((a[mid] - a[i]) * (c - a[i]) > 0 && dis(a[i], a[mid])) {
					r = mid;
				} else {
					l = mid + 1;
				} 
			}
			ans = max(ans, get(l, n));
		} else {
			int l, r;
			if ((a[1] - a[i]) * (c - a[i]) < 0) {
				l = 1, r = i - 1;
			} else {
				l = i + 1, r = n;
			}			
			while (l < r) {
				int mid = l + r + 1 >> 1;
				if ((a[mid] - a[i]) * (c - a[i]) < 0 && dis(a[i], a[mid])) {
					l = mid;
				} else {
					r = mid - 1;
				}
			}
			ans = max(ans, get(i, l));
			if ((a[n] - a[i]) * (c - a[i]) > 0) {
				l = i + 1, r = n;
			} else {
				l = 1, r = i - 1;
			}
			while (l < r) {
				int mid = l + r >> 1;
				if ((a[mid] - a[i]) * (c - a[i]) > 0 && dis(a[i], a[mid])) {
					r = mid;
				} else {
					l = mid + 1;
				}
			}
			ans = max(ans, get(l, i));
		}
	}
	cout << ans << '\n';
	// cerr << "case end\n";
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> T;
	while (T--) {
		work();
	}

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6240kb

input:

3
5
1 1 1
0 0
1 0
5 0
3 3
0 5
6
2 4 1
2 0
4 0
6 3
4 6
2 6
0 3
4
3 3 1
3 0
6 3
3 6
0 3

output:

5
24
0

result:

ok 3 number(s): "5 24 0"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 6252kb

input:

1
6
0 0 499999993
197878055 -535013568
696616963 -535013568
696616963 40162440
696616963 499999993
-499999993 499999993
-499999993 -535013568

output:

1238514776782540316

result:

wrong answer 1st numbers differ - expected: '0', found: '1238514776782540316'