답안 #25760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25760 2017-06-24T05:23:48 Z zigui 별자리 2 (JOI14_constellation2) C++14
100 / 100
1483 ms 1480 KB
#include<stdio.h>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

pii operator-(const pii &l, const pii &r){
	return pii(l.first - r.first, l.second - r.second);
}

ll operator/(const pii &l, const pii &r){
	return (ll)l.first * r.second - (ll)l.second * r.first;
}

int sign(pii x){ return pii(0, 0) < x ? 1 : -1; }

const int MX = 3005;

struct star{
	star(){}
	star(pii p, int c):p(p), c(c){}
	pii p;
	int c;
}D[MX];
int N;

ll getm(int x[3], int y[3], int c1, int c2){
	ll m = 1;
	for(int i = 0; i < 3; i++){
		if( c1 != i ) m *= x[i];
		if( c2 != i ) m *= y[i];
	}
	return m;
}

ll solve(vector<star> &L, int c){
	int x[3] = {}, y[3] = {};
	sort(L.begin(), L.end(), [](star l, star r){
		return sign(l.p) != sign(r.p) ? sign(l.p) > sign(r.p) : l.p/r.p > 0;
	});
	int N = L.size();
	ll ans = 0;
	for(int i = 0; i < N; i++) L.push_back(L[i]);
	int r = 0;
	for(int i = 0; i < N; i++) y[L[i].c]++;
	for(int i = 0; i < N; i++){
		while(r < i+N && L[i].p/L[r].p >= 0 ){
			x[L[r].c]++; y[L[r].c]--;
			r++;
		}
		ans += getm(x, y, L[i].c, c);
		x[L[i].c]--; y[L[i].c]++;
	}
	return ans;
}

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d%d%d", &D[i].p.first, &D[i].p.second, &D[i].c);
	ll ans = 0;
	for(int i = 1; i <= N; i++){
		vector<star> L;
		for(int j = 1; j <= N; j++){
			if( i != j ) L.emplace_back(D[j].p - D[i].p, D[j].c);
		}
		ans += solve(L, D[i].c);
	}
	printf("%lld\n", ans/2);
}

Compilation message

constellation2.cpp: In function 'int main()':
constellation2.cpp:62:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
constellation2.cpp:63:85: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= N; i++) scanf("%d%d%d", &D[i].p.first, &D[i].p.second, &D[i].c);
                                                                                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1212 KB Output is correct
2 Correct 0 ms 1212 KB Output is correct
3 Correct 0 ms 1212 KB Output is correct
4 Correct 0 ms 1212 KB Output is correct
5 Correct 0 ms 1212 KB Output is correct
6 Correct 0 ms 1212 KB Output is correct
7 Correct 0 ms 1212 KB Output is correct
8 Correct 0 ms 1212 KB Output is correct
9 Correct 0 ms 1212 KB Output is correct
10 Correct 0 ms 1212 KB Output is correct
11 Correct 0 ms 1212 KB Output is correct
12 Correct 0 ms 1212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1212 KB Output is correct
2 Correct 0 ms 1212 KB Output is correct
3 Correct 0 ms 1212 KB Output is correct
4 Correct 0 ms 1212 KB Output is correct
5 Correct 3 ms 1212 KB Output is correct
6 Correct 9 ms 1212 KB Output is correct
7 Correct 9 ms 1212 KB Output is correct
8 Correct 9 ms 1212 KB Output is correct
9 Correct 9 ms 1212 KB Output is correct
10 Correct 6 ms 1212 KB Output is correct
11 Correct 9 ms 1212 KB Output is correct
12 Correct 9 ms 1212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 1212 KB Output is correct
2 Correct 99 ms 1212 KB Output is correct
3 Correct 133 ms 1212 KB Output is correct
4 Correct 146 ms 1212 KB Output is correct
5 Correct 309 ms 1384 KB Output is correct
6 Correct 576 ms 1384 KB Output is correct
7 Correct 1086 ms 1480 KB Output is correct
8 Correct 1429 ms 1480 KB Output is correct
9 Correct 1483 ms 1480 KB Output is correct
10 Correct 1419 ms 1480 KB Output is correct
11 Correct 1269 ms 1480 KB Output is correct
12 Correct 1399 ms 1480 KB Output is correct
13 Correct 1436 ms 1480 KB Output is correct
14 Correct 1346 ms 1480 KB Output is correct
15 Correct 1386 ms 1480 KB Output is correct
16 Correct 1329 ms 1480 KB Output is correct