Submission #168988

#TimeUsernameProblemLanguageResultExecution timeMemory
168988kostia244Triangles (CEOI18_tri)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#include "trilib.h"
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using vi = vector<int>;
const int mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace local {
	int p = -1;
	using vec = complex<int>;
	int cross(vec a, vec b) {
		return (conj(a)*b).imag();
	}
	vector<vec> v;
	int N;
	int get_n() {
		cin >> N;
//		N = 20;
		v.resize(N);
		for(auto &i : v) {
			int x, y;
			cin >> x >> y;
//			x = rng()%100, y = rng()%100;
			i = vec(x, y);
		}
		return N;
	}
	void give_answer(int x) {
		if(p!=-1&&p!=x) {
			cout << "WA\n";
			cout << N << "\n";
			for(auto i : v)
				cout << i.real() << " " << i.imag() << "\n";
		}
		cout << "ANSWER:" << x << "\n";
		p=x;
	}
	bool is_clockwise(int a, int b, int c) {
//		cerr << a << " " << b << " " << c << "\n";
		if(a!=b&&b!=c&&c!=a)
		assert(cross(v[b-1]-v[a-1], v[c-1]-v[a-1]));
		return cross(v[b-1]-v[a-1], v[c-1]-v[a-1])>0;
	}
}
//using namespace local;
int n;
int check(int a) {
	int b = 1+(a==1);
	for(int i = 1; i <= n; i++)
		if(i!=a&&i!=b&&is_clockwise(a, b, i))
			b = i;
	for(int i = 1; i <= n; i++)
		if(i!=a&&i!=b&&is_clockwise(a, b, i))
			return 0;
	return 1;
}
vi hull(vi v, int V) {
    sort(all(v), [&](const int& a, const int &b) {
		return !is_clockwise(V, a, b);
	});
	vi hull = {V};
	for(auto i : v) {
		while(hull.size()>1&&is_clockwise(hull[hull.size()-2], hull.back(), i))
			hull.pop_back();
		hull.pb(i);
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	n = get_n();
	vi a[2];
	a[0].pb(2);
	for(int i = 3; i <= n; i++) a[is_clockwise(1, 2, i)].pb(i);
	vi x = hull(a[0], 1), y = hull(a[1], 1);
    reverse(all(y));//0 = top, 1 = bottom
    while(a.size()&&b.size()) {
        if(a.size()==1&&b.size()==1) break;
        int A = a.size(), B = b.size();
        if(A>1&&is_clockwise(a[A-2], a[A-1], b[B-1])) {
            a.pop_back();
        }
        if(B>1&&is_clockwise(a[A-1], b[B-1], b[B-2])) {
            b.pop_back();
        }
    }
    reverse(all(x)), reverse(all(y));
    while(a.size()&&b.size()) {
        if(a.size()==1&&b.size()==1) break;
        int A = a.size(), B = b.size();
        if(A>1&&!is_clockwise(a[A-2], a[A-1], b[B-1])) {
            a.pop_back();
        }
        if(B>1&&!is_clockwise(a[A-1], b[B-1], b[B-2])) {
            b.pop_back();
        }
    }
    give_answer(a.size()+b.size());
}

Compilation message (stderr)

tri.cpp: In function 'vi hull(vi, int)':
tri.cpp:70:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
tri.cpp: In function 'int main()':
tri.cpp:81:13: error: request for member 'size' in 'a', which is of non-class type 'vi [2] {aka std::vector<int> [2]}'
     while(a.size()&&b.size()) {
             ^~~~
tri.cpp:81:21: error: 'b' was not declared in this scope
     while(a.size()&&b.size()) {
                     ^
tri.cpp:82:14: error: request for member 'size' in 'a', which is of non-class type 'vi [2] {aka std::vector<int> [2]}'
         if(a.size()==1&&b.size()==1) break;
              ^~~~
tri.cpp:83:19: error: request for member 'size' in 'a', which is of non-class type 'vi [2] {aka std::vector<int> [2]}'
         int A = a.size(), B = b.size();
                   ^~~~
tri.cpp:84:48: error: 'B' was not declared in this scope
         if(A>1&&is_clockwise(a[A-2], a[A-1], b[B-1])) {
                                                ^
tri.cpp:85:15: error: request for member 'pop_back' in 'a', which is of non-class type 'vi [2] {aka std::vector<int> [2]}'
             a.pop_back();
               ^~~~~~~~
tri.cpp:87:12: error: 'B' was not declared in this scope
         if(B>1&&is_clockwise(a[A-1], b[B-1], b[B-2])) {
            ^
tri.cpp:92:13: error: request for member 'size' in 'a', which is of non-class type 'vi [2] {aka std::vector<int> [2]}'
     while(a.size()&&b.size()) {
             ^~~~
tri.cpp:92:21: error: 'b' was not declared in this scope
     while(a.size()&&b.size()) {
                     ^
tri.cpp:93:14: error: request for member 'size' in 'a', which is of non-class type 'vi [2] {aka std::vector<int> [2]}'
         if(a.size()==1&&b.size()==1) break;
              ^~~~
tri.cpp:94:19: error: request for member 'size' in 'a', which is of non-class type 'vi [2] {aka std::vector<int> [2]}'
         int A = a.size(), B = b.size();
                   ^~~~
tri.cpp:95:49: error: 'B' was not declared in this scope
         if(A>1&&!is_clockwise(a[A-2], a[A-1], b[B-1])) {
                                                 ^
tri.cpp:96:15: error: request for member 'pop_back' in 'a', which is of non-class type 'vi [2] {aka std::vector<int> [2]}'
             a.pop_back();
               ^~~~~~~~
tri.cpp:98:12: error: 'B' was not declared in this scope
         if(B>1&&!is_clockwise(a[A-1], b[B-1], b[B-2])) {
            ^
tri.cpp:102:19: error: request for member 'size' in 'a', which is of non-class type 'vi [2] {aka std::vector<int> [2]}'
     give_answer(a.size()+b.size());
                   ^~~~
tri.cpp:102:26: error: 'b' was not declared in this scope
     give_answer(a.size()+b.size());
                          ^