Submission #38271

# Submission time Handle Problem Language Result Execution time Memory
38271 2018-01-03T10:12:02 Z youngyojun 별자리 2 (JOI14_constellation2) C++11
100 / 100
1396 ms 2076 KB
#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

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 time Memory Grader output
1 Correct 0 ms 2076 KB Output is correct
2 Correct 0 ms 2076 KB Output is correct
3 Correct 0 ms 2076 KB Output is correct
4 Correct 0 ms 2076 KB Output is correct
5 Correct 0 ms 2076 KB Output is correct
6 Correct 0 ms 2076 KB Output is correct
7 Correct 0 ms 2076 KB Output is correct
8 Correct 0 ms 2076 KB Output is correct
9 Correct 0 ms 2076 KB Output is correct
10 Correct 0 ms 2076 KB Output is correct
11 Correct 0 ms 2076 KB Output is correct
12 Correct 0 ms 2076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2076 KB Output is correct
2 Correct 0 ms 2076 KB Output is correct
3 Correct 0 ms 2076 KB Output is correct
4 Correct 0 ms 2076 KB Output is correct
5 Correct 3 ms 2076 KB Output is correct
6 Correct 9 ms 2076 KB Output is correct
7 Correct 6 ms 2076 KB Output is correct
8 Correct 6 ms 2076 KB Output is correct
9 Correct 29 ms 2076 KB Output is correct
10 Correct 6 ms 2076 KB Output is correct
11 Correct 9 ms 2076 KB Output is correct
12 Correct 6 ms 2076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 2076 KB Output is correct
2 Correct 103 ms 2076 KB Output is correct
3 Correct 123 ms 2076 KB Output is correct
4 Correct 116 ms 2076 KB Output is correct
5 Correct 286 ms 2076 KB Output is correct
6 Correct 543 ms 2076 KB Output is correct
7 Correct 856 ms 2076 KB Output is correct
8 Correct 1276 ms 2076 KB Output is correct
9 Correct 1313 ms 2076 KB Output is correct
10 Correct 1269 ms 2076 KB Output is correct
11 Correct 1246 ms 2076 KB Output is correct
12 Correct 1256 ms 2076 KB Output is correct
13 Correct 1273 ms 2076 KB Output is correct
14 Correct 1396 ms 2076 KB Output is correct
15 Correct 1319 ms 2076 KB Output is correct
16 Correct 1319 ms 2076 KB Output is correct