Submission #31609

# Submission time Handle Problem Language Result Execution time Memory
31609 2017-08-30T03:15:46 Z khsoo01 별자리 2 (JOI14_constellation2) C++11
100 / 100
1993 ms 72684 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 3005;

ll n, x[N], y[N], c[N], p[2*N], t[3], d[N][N], ans;

ll ccw (ll A, ll B, ll C) {
	return (x[A]*y[B]+x[B]*y[C]+x[C]*y[A])-(y[A]*x[B]+y[B]*x[C]+y[C]*x[A]);
}

bool isup (ll I) {
	return (x[I] >= x[p[1]] && y[I] >= y[p[1]]) || y[I] > y[p[1]];
}

bool cmp (ll A, ll B) {
	bool ba = isup(A), bb = isup(B);
	if(ba != bb) return ba;
	return ccw(p[1], A, B) > 0;
}

int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) {
		scanf("%lld%lld%lld",&x[i],&y[i],&c[i]);
	}
	for(ll i=1;i<=n;i++) {
		for(ll j=1;j<=n;j++) {
			p[j] = j;
		}
		swap(p[1], p[i]);
		sort(p+2, p+1+n, cmp);
		for(ll j=2;j<=n;j++) {
			p[n+j-1] = p[j];
		}
		p[2*n] = p[2];
		ll E = 2; t[0] = t[1] = t[2] = 0;
		for(ll j=2;j<=n;j++) {
			t[c[p[j]]]--;
			while(ccw(i, p[j], p[E]) >= 0 && E < j+n-1) {
				t[c[p[E]]]++; E++;
			}
			d[i][p[j]] = 1;
			for(ll k=0;k<3;k++) {
				if(k != c[i]) d[i][p[j]] *= t[k];
			}
		}
	}
	for(ll i=1;i<=n;i++) {
		for(ll j=1;j<=n;j++) {
			ans += d[i][j] * d[j][i];
		}
	}
	printf("%lld\n",ans/2);
}

Compilation message

constellation2.cpp: In function 'int main()':
constellation2.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
                  ^
constellation2.cpp:26:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld",&x[i],&y[i],&c[i]);
                                          ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72684 KB Output is correct
2 Correct 0 ms 72684 KB Output is correct
3 Correct 0 ms 72684 KB Output is correct
4 Correct 0 ms 72684 KB Output is correct
5 Correct 0 ms 72684 KB Output is correct
6 Correct 0 ms 72684 KB Output is correct
7 Correct 0 ms 72684 KB Output is correct
8 Correct 0 ms 72684 KB Output is correct
9 Correct 0 ms 72684 KB Output is correct
10 Correct 0 ms 72684 KB Output is correct
11 Correct 0 ms 72684 KB Output is correct
12 Correct 0 ms 72684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72684 KB Output is correct
2 Correct 0 ms 72684 KB Output is correct
3 Correct 0 ms 72684 KB Output is correct
4 Correct 3 ms 72684 KB Output is correct
5 Correct 6 ms 72684 KB Output is correct
6 Correct 13 ms 72684 KB Output is correct
7 Correct 13 ms 72684 KB Output is correct
8 Correct 13 ms 72684 KB Output is correct
9 Correct 13 ms 72684 KB Output is correct
10 Correct 9 ms 72684 KB Output is correct
11 Correct 13 ms 72684 KB Output is correct
12 Correct 6 ms 72684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 72684 KB Output is correct
2 Correct 143 ms 72684 KB Output is correct
3 Correct 179 ms 72684 KB Output is correct
4 Correct 173 ms 72684 KB Output is correct
5 Correct 419 ms 72684 KB Output is correct
6 Correct 789 ms 72684 KB Output is correct
7 Correct 1359 ms 72684 KB Output is correct
8 Correct 1993 ms 72684 KB Output is correct
9 Correct 1943 ms 72684 KB Output is correct
10 Correct 1909 ms 72684 KB Output is correct
11 Correct 1903 ms 72684 KB Output is correct
12 Correct 1916 ms 72684 KB Output is correct
13 Correct 1909 ms 72684 KB Output is correct
14 Correct 1933 ms 72684 KB Output is correct
15 Correct 1789 ms 72684 KB Output is correct
16 Correct 1966 ms 72684 KB Output is correct