# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
141313 |
2019-08-07T12:11:40 Z |
tutis |
Tri (CEOI09_tri) |
C++17 |
|
1103 ms |
37740 KB |
/*input
4 3
1 2
1 3
5 1
5 3
1 4 3 3
2 2 4 1
4 4 6 3
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct point
{
ll x, y;
point() {}
point(ll x, ll y): x(x), y(y) {}
int d()
{
return x + y;
}
};
point operator-(point a, point b)
{
return point(a.x - b.x, a.y - b.y);
}
point operator-(point b)
{
return point(-b.x, -b.y);
}
ll cross(point a, point b)
{
return a.x * b.y - a.y * b.x;
}
int sgn(ll x)
{
if (x < 0)
return -1;
if (x > 0)
return 1;
return 0;
}
void fix(vector<point>& X)
{
if (X.size() >= 2)
{
if (cross(X.back(), X[X.size() - 2]) == 0)
{
if (X.back().d() < X[X.size() - 2].d())
{
X.erase(X.end() - 2);
return fix(X);
}
else
{
X.erase(--X.end());
return;
}
}
}
if (X.size() >= 3)
{
if (cross(X[X.size() - 1] - X[X.size() - 2], X[X.size() - 2] - X[X.size() - 3]) >= 0)
{
X.erase(X.end() - 2);
return fix(X);
}
}
}
struct DS
{
DS *left = NULL, *right = NULL;
vector<point>X;
DS(point A[], int i, int j)
{
if (i < j)
{
left = new DS(A, i, (i + j) / 2);
right = new DS(A, (i + j) / 2 + 1, j);
}
for (int k = i; k <= j; k++)
{
X.push_back(A[k]);
fix(X);
}
}
int get(point A, point B)
{
if (cross(B, X[0]) < 0)
return 0;
if (cross(X.back(), A) < 0)
return 0;
if (cross(A, X[0]) < 0 && cross(X.back(), B) < 0)
{
for (point C : X)
if (cross(B - A, C - A) > 0)
return 1;
return 0;
}
if (left)
return left->get(A, B) + right->get(A, B);
return 0;
}
};
int main()
{
int K, M;
cin >> K >> M;
point A[K];
for (point &i : A)
cin >> i.x >> i.y;
sort(A, A + K, [&](point a, point b) {return cross(a, b) < 0;});
DS medis(A, 0, K - 1);
while (M--)
{
point A, B;
cin >> A.x >> A.y >> B.x >> B.y;
if (cross(A, B) > 0)
swap(A, B);
if (medis.get(A, B) > 0)
cout << "Y\n";
else
cout << "N\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
2 |
Incorrect |
8 ms |
632 KB |
Output isn't correct |
3 |
Incorrect |
194 ms |
8056 KB |
Output isn't correct |
4 |
Incorrect |
347 ms |
19724 KB |
Output isn't correct |
5 |
Incorrect |
695 ms |
37740 KB |
Output isn't correct |
6 |
Incorrect |
830 ms |
22468 KB |
Output isn't correct |
7 |
Incorrect |
1103 ms |
28280 KB |
Output isn't correct |
8 |
Incorrect |
824 ms |
28024 KB |
Output isn't correct |
9 |
Incorrect |
961 ms |
30760 KB |
Output isn't correct |
10 |
Incorrect |
1025 ms |
33384 KB |
Output isn't correct |