Submission #594842

#TimeUsernameProblemLanguageResultExecution timeMemory
594842penguinhackerTriangles (CEOI18_tri)C++17
20 / 100
1 ms212 KiB
#include <bits/stdc++.h>
#include "trilib.h"
using namespace std;

#define ll long long
#define ar array

// solution idea: find any point on the hull
// after this just use graham scan: sort by angle and then sweep

int n;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	n=get_n();
	/*int a=1, b=2, c=3;
	for (int i=4; i<=n; ++i) {
		bool s1=is_clockwise(a, b, i), s2=is_clockwise(b, c, i), s3=is_clockwise(c, a, i), s4=is_clockwise(a, b, c);
		for (int rep=0; rep<3; ++rep) {
			if (s1==s3&&s1!=s4) {
				a=i;
				break;
			}
			swap(s1, s2);
			swap(s2, s3);
			swap(a, b);
			swap(b, c);
		}
	}*/
	vector<int> part[2];
	for (int i=3; i<=n; ++i)
		part[is_clockwise(1, 2, i)].push_back(i);
	int fix;
	if (part[0].empty()||part[1].empty())
		fix=1;
	else {
		fix=part[1][0];
		for (int i=1; i<part[1].size(); ++i)
			if (is_clockwise(1, fix, part[1][i]))
				fix=part[1][i];
	}
	vector<int> points;
	for (int i=1; i<=n; ++i)
		if (i!=fix)
			points.push_back(i);
	sort(points.begin(), points.end(), [&](int i, int j) { return is_clockwise(fix, j, i); });
	vector<int> hull={fix};
	for (int i : points) {
		while(hull.size()>=2&&is_clockwise(hull.end()[-2], hull.back(), i))
			hull.pop_back();
		hull.push_back(i);
	}
	give_answer(hull.size());
	return 0;
}

Compilation message (stderr)

tri.cpp: In function 'int main()':
tri.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for (int i=1; i<part[1].size(); ++i)
      |                 ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...