답안 #135938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135938 2019-07-24T14:06:50 Z onjo0127 Tri (CEOI09_tri) C++11
50 / 100
125 ms 7928 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define X first
#define Y second
#define sz(V) ((int)V.size())
 
int CCW(pll A, pll B, pll C) {
	long long tmp = A.X*B.Y + B.X*C.Y + C.X*A.Y - A.Y*B.X - B.Y*C.X - C.Y*A.X;
	if(tmp < 0LL) return -1;
	if(tmp == 0LL) return 0;
	if(tmp > 0LL) return +1;
}
 
pll add(pll A, pll B, pll C) {
	return {A.X + C.X - B.X, A.Y + C.Y - B.Y};
}

bool chk(vector<pll> &H, pll A, pll B) {
	if(CCW({0, 0}, A, B) == 1) swap(A, B);
	bool f = 0;
	int l = 0, r = sz(H) - 1;
	while(l <= r) {
		int m = l+r >> 1;
		if(CCW(A, B, H[m]) == -1) f = 1;
		if(m+1 == sz(H) || CCW(A, B, add(B, H[m], H[m+1])) == 1) r = m-1;
		else l = m+1;
	}
	return f;
}

pll P[100009];
 
int main() {
	int K, M; scanf("%d%d",&K,&M);
	for(int i=1; i<=K; i++) scanf("%lld%lld", &P[i].X, &P[i].Y);
	sort(P+1, P+K+1);
	vector<pll> H;
	for(int i=1; i<=K; i++) {
		while(sz(H) >= 2 && CCW(H[sz(H) - 2], H[sz(H) - 1], P[i]) <= 0) H.pop_back();
		H.push_back(P[i]);
	}
	for(int i=1; i<=M; i++) {
		pll A, B; scanf("%lld%lld%lld%lld", &A.X, &A.Y, &B.X, &B.Y);
		if(chk(H, A, B)) puts("Y");
		else puts("N");
	}
	return 0;
}

Compilation message

tri.cpp: In function 'bool chk(std::vector<std::pair<long long int, long long int> >&, pll, pll)':
tri.cpp:25:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l+r >> 1;
           ~^~
tri.cpp: In function 'int CCW(pll, pll, pll)':
tri.cpp:14:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
tri.cpp: In function 'int main()':
tri.cpp:36:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int K, M; scanf("%d%d",&K,&M);
            ~~~~~^~~~~~~~~~~~~~
tri.cpp:37:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=K; i++) scanf("%lld%lld", &P[i].X, &P[i].Y);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tri.cpp:45:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   pll A, B; scanf("%lld%lld%lld%lld", &A.X, &A.Y, &B.X, &B.Y);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 380 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 29 ms 1876 KB Output is correct
4 Correct 64 ms 3824 KB Output is correct
5 Correct 125 ms 7020 KB Output is correct
6 Incorrect 83 ms 5880 KB Output isn't correct
7 Incorrect 111 ms 7672 KB Output isn't correct
8 Incorrect 95 ms 6412 KB Output isn't correct
9 Incorrect 104 ms 7160 KB Output isn't correct
10 Incorrect 120 ms 7928 KB Output isn't correct