Submission #38271

#TimeUsernameProblemLanguageResultExecution timeMemory
38271youngyojun별자리 2 (JOI14_constellation2)C++11
100 / 100
1396 ms2076 KiB
#include <bits/stdc++.h>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define clv(V) (V).clear()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
ll operator * (const pll& a, const pll& b) {
	return a.first*b.second - b.first*a.second;
}
ll ccw(const pll& a, const pll& b, const pll& c) {
	return a*b + b*c + c*a;
}

const int MAXN = 3005;

vector<int> VA, VB;
int C[2][3];

pll P[MAXN];
int A[MAXN];

ll Ans;
int N;

void g(int c1, int c2) {
	int tmp1 = C[0][c1], tmp2 = C[1][c2];
	C[0][c1] = C[1][c2] = 1;
	Ans += (ll)C[0][0] * C[0][1] * C[0][2] * C[1][0] * C[1][1] * C[1][2];
	C[0][c1] = tmp1; C[1][c2] = tmp2;
	tmp1 = C[1][c1]; tmp2 = C[0][c2];
	C[1][c1] = C[0][c2] = 1;
	Ans += (ll)C[0][0] * C[0][1] * C[0][2] * C[1][0] * C[1][1] * C[1][2];
	C[1][c1] = tmp1; C[0][c2] = tmp2;
}
void f() {
	clv(VA); clv(VB);
	for(int i = 0; i < 3; i++) C[0][i] = C[1][i] = 0;
	VA.pb(N); C[0][A[N]]++;
	for(int i = 2; i < N; i++) {
		const ll dt = ccw(P[1], P[N], P[i]);
		if(0 < dt) {
			VA.pb(i); C[0][A[i]]++;
		} else {
			VB.pb(i); C[1][A[i]]++;
		}
	}
	auto cmp = [&](int a, int b) -> bool {
		return 0 < ccw(P[1], P[a], P[b]);
	};
	sort(VA.begin()+1, VA.end(), cmp);
	sort(allv(VB), cmp);
	revv(VA); revv(VB);
	for(; !VA.empty() || !VB.empty();) {
		if(!VA.empty() && (VB.empty() || ccw(P[VB.back()], P[1], P[VA.back()]) < 0)) {
			const int idx = VA.back(); VA.pop_back();
			C[0][A[idx]]--;
			g(A[1], A[idx]);
			C[1][A[idx]]++;
		} else {
			const int idx = VB.back(); VB.pop_back();
			C[1][A[idx]]--;
			g(A[1], A[idx]);
			C[0][A[idx]]++;
		}
	}
}
int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) {
		scanf("%lld%lld", &P[i].first, &P[i].second);
		scanf("%d", &A[i]);
	}
	f(); for(int i = 2; i <= N; i++) {
		swap(P[1], P[i]); swap(A[1], A[i]);
		f();
	}
	printf("%lld\n", Ans/4);
	return 0;
}

Compilation message (stderr)

constellation2.cpp: In function 'int main()':
constellation2.cpp:72:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
constellation2.cpp:74:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &P[i].first, &P[i].second);
                                               ^
constellation2.cpp:75:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &A[i]);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...