QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#343591#7730. Convex Checker5abWA 17ms6780kbC++202.0kb2024-03-02 19:58:212024-03-02 19:58:21

Judging History

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

  • [2024-07-04 19:27:17]
  • hack成功,自动添加数据
  • (/hack/727)
  • [2024-07-04 19:17:30]
  • hack成功,自动添加数据
  • (/hack/726)
  • [2024-03-02 19:58:21]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:6780kb
  • [2024-03-02 19:58:21]
  • 提交

answer

/* name: 7730
 * author: 5ab
 * created at: 2024-03-02
 */
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))

auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (y < x) x = y; };

using ll = long long;
const int N = 2e5;

struct point
{
	int x, y;
	point operator-(const point& q) const {
		return { x - q.x, y - q.y };
	}
	bool operator==(const point& q) const {
		return x == q.x && y == q.y;
	}
}
a[N], b[N];

inline ll cross(const point& p, const point& q) {
	return 1ll * p.x * q.y - 1ll * q.x * p.y;
}
inline ll dot(const point& p, const point& q) {
	return 1ll * p.x * q.x + 1ll * p.y * q.y;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i].x >> a[i].y;
	copy(a, a + n, b);
	
	swap(b[0], *min_element(b, b + n, [](auto& p, auto& q) {
		return p.x == q.x ? p.y < q.y : p.x < q.x;
	}));
	sort(b + 1, b + n, [&](auto& p, auto& q) {
		ll t = cross(p - a[0], q - a[0]);
		return t ? t > 0 : dot(q - p, p - a[0]) > 0;
	});
	
	int lm = unique(b, b + n) - b;
	vector<point> cv;
	for (int i = 0; i < lm; i++)
	{
		while (ssz(cv) > 1 && cross(b[i] - cv.back(), cv.back() - end(cv)[-2]) >= 0)
			cv.pop_back();
		// cerr << b[i].x << " " << b[i].y << endl;
		cv.push_back(b[i]);
	}
	
	// cerr << ssz(cv) << " " << lm << endl;
	
	if (ssz(cv) != n)
	{
		cout << "No\n";
		return 0;
	}
	auto check = [&]() -> bool
	{
		int sp = find(a, a + n, cv[0]) - a;
		// cerr << sp << endl;
		if (sp == n)
			return 0;
		for (int i = 0, j = sp; i < n; i++, j = (j + 1) % n)
			if (a[j] != cv[i])
			{
				// cerr << i << " " << j << " " << cv[i].x << " " << cv[i].y << endl;
				return 0;
			}
		return 1;
	};
	
	bool res = check();
	reverse(all(cv));
	
	cout << ((check() || res) ? "Yes" : "No") << "\n";
	
	return 0;
}
// started coding at: 03-02 19:14:06

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 5892kb

input:

3
0 0
1 0
0 1

output:

Yes

result:

ok answer is YES

Test #2:

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

input:

4
0 0
0 1
1 1
1 0

output:

Yes

result:

ok answer is YES

Test #3:

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

input:

4
0 0
0 3
1 2
1 1

output:

Yes

result:

ok answer is YES

Test #4:

score: 0
Accepted
time: 1ms
memory: 3832kb

input:

3
0 0
0 0
0 0

output:

No

result:

ok answer is NO

Test #5:

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

input:

5
1 0
4 1
0 1
2 0
3 2

output:

No

result:

ok answer is NO

Test #6:

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

input:

5
0 0
1000000000 0
1000000000 500000000
1000000000 1000000000
0 1000000000

output:

No

result:

ok answer is NO

Test #7:

score: 0
Accepted
time: 1ms
memory: 5840kb

input:

5
0 0
1000000000 0
1000000000 499999999
1000000000 1000000000
0 1000000000

output:

No

result:

ok answer is NO

Test #8:

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

input:

5
0 0
999999999 0
1000000000 50000000
999999999 1000000000
0 1000000000

output:

Yes

result:

ok answer is YES

Test #9:

score: -100
Wrong Answer
time: 17ms
memory: 6780kb

input:

128312
5578014 410408218
5585076 410404717
5588011 410403262
5588473 410403033
5589740 410402405
5593295 410400643
5593751 410400417
5597248 410398684
5598935 410397848
5600618 410397014
5605185 410394751
5610514 410392111
5614281 410390245
5617263 410388768
5621142 410386847
5630840 410382045
56310...

output:

No

result:

wrong answer expected YES, found NO