QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#241845#7730. Convex CheckerfstqwqWA 0ms3748kbC++141.2kb2023-11-06 18:28:322023-11-06 18:28:32

Judging History

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

  • [2024-07-04 19:27:17]
  • hack成功,自动添加数据
  • (/hack/727)
  • [2024-07-04 19:17:30]
  • hack成功,自动添加数据
  • (/hack/726)
  • [2023-11-06 18:28:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3748kb
  • [2023-11-06 18:28:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair <int, int> pii;



#define cp const point &
struct point {
	LL x, y;
	point () {}
	point (LL xx, LL yy) { x = xx, y = yy; }
	point operator + (cp a) const { return {x + a.x, y + a.y}; }
	point operator - (cp a) const { return {x - a.x, y - a.y}; }
	bool operator < (cp a) const {
		return make_pair(x, y) < make_pair(a.x, a.y);
	}
};

LL det (point a, point b) {
	return a.x * b.y - b.x * a.y;
}
int sgn(LL x) {
	return x > 0 ? 1 : (x < 0 ? -1 : 0);
}
bool isconvex(vector <point> &p) {
	bool s[3];
	int n = (int) p.size();
	memset(s, false, sizeof(s));
	for (int i = 0; i < n; i++) {
		int j = (i + 1) % n;
		int k = (j + 1) % n;
		s[sgn(det(p[j] - p[i], p[k] - p[i])) + 1] = true;
		if (s[0] && s[2]) return false;
	}
	return !s[1];
}

void work () {
	int n;
	cin >> n;
	vector <point> a;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		a.push_back({x, y});
	}
	if (det(a[1] - a[0], a[2] - a[0]) < 0) reverse(a.begin(), a.end());

	puts (isconvex(a) ? "Yes" : "No");
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
	for (int ca = 1; ca <= T; ca ++)
		work();
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0 0
1 0
0 1

output:

Yes

result:

ok answer is YES

Test #2:

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

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

input:

4
0 0
0 3
1 2
1 1

output:

Yes

result:

ok answer is YES

Test #4:

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

input:

3
0 0
0 0
0 0

output:

No

result:

ok answer is NO

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3748kb

input:

5
1 0
4 1
0 1
2 0
3 2

output:

Yes

result:

wrong answer expected NO, found YES