# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38271 | youngyojun | 별자리 2 (JOI14_constellation2) | C++11 | 1396 ms | 2076 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |