QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#242312 | #7730. Convex Checker | invaded | WA | 37ms | 19216kb | C++17 | 4.5kb | 2023-11-07 09:46:08 | 2023-11-07 09:46:08 |
Judging History
你现在查看的是最新测评结果
- [2024-07-04 19:27:17]
- hack成功,自动添加数据
- (/hack/727)
- [2024-07-04 19:17:30]
- hack成功,自动添加数据
- (/hack/726)
- [2023-12-08 14:40:48]
- hack成功,自动添加数据
- (//qoj.ac/hack/493)
- [2023-11-07 10:32:52]
- hack成功,自动添加数据
- (//qoj.ac/hack/426)
- [2023-11-07 10:28:41]
- hack成功,自动添加数据
- (//qoj.ac/hack/425)
- [2023-11-07 09:46:08]
- 提交
answer
#include<bits/stdc++.h>
#ifndef xxx
#define dbg(...) ;
#endif
using namespace std;
//template<class T> ostream &operator<<(ostream &o, const vector <T> &v) { bool f=false; for(T i:v) { f?o<<' ':o; o<<(i); f=true; } return o; }
template<class T> void sort(T &v) { std::sort(v.begin(), v.end()); }
template<class T, class C> void sort(T &v, C c) { std::sort(v.begin(), v.end(), c); }
template<class T> void reverse(T &v) { std::reverse(v.begin(), v.end()); }
template<class T> bool is_sorted(T &v) { return std::is_sorted(v.begin(), v.end()); }
template<class T> inline void _min(T &x, const T &y) { x>y?x=y:x; }
template<class T> inline void _max(T &x, const T &y) { x<y?x=y:x; }
istream &operator>>(istream &i, __int128_t &x) { x=0; short f=1; char c=0; while(!isdigit(c)) { if(c=='-')f=-1; c=i.get(); } while(isdigit(c))x=x*10+c-'0', c=i.get(); x*=f; return i; }
ostream &operator<<(ostream &o, __int128_t x) { if(x==0) { o<<0; return o; } bool f=false; string s; if(x<0)f=true, x=-x; while(x)s+=x%10+'0', x/=10; reverse(s); if(f)o<<'-'; o<<s; return o; }
mt19937 mt(time(0));
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
constexpr int maxn=2e5+5;
constexpr int mod=1e9+7;
constexpr int inf=0x3f3f3f3f;
constexpr ll INF=0x3f3f3f3f3f3f3f3fll;
constexpr double pi=acos(-1.0);
constexpr double eps=1e-9;
struct Point
{
ll x, y;
void read()
{
cin>>x>>y;
}
bool operator<(const Point &p)const
{
return x==p.x?y<p.y:x<p.x;
}
bool operator==(const Point &p)const
{
return x==p.x&&y==p.y;
}
friend ostream &operator<<(ostream &o, const Point &p)
{
o<<'('<<p.x<<','<<p.y<<')';
return o;
}
};
struct Vect
{
ll x, y;
Vect() :x(0), y(0) {}
Vect(Point st, Point ed) :x(ed.x-st.x), y(ed.y-st.y) {}
ll dot(Vect V)
{
return x*V.x+y*V.y;
}
ll cross(Vect V)
{
return x*V.y-y*V.x;
}
ll toLeft(Vect V)
{
ll t=cross(V);
return (t>0)-(t<0);
}
};
Vect operator-(Point ed, Point st)
{
return Vect(st, ed);
}
vector<Point> convexHull1(vector<Point> p)
{
vector<Point> st;
if(p.empty()) return st;
sort(p.begin(), p.end());
const auto check=[](const vector<Point> &st, const Point &u)
{
const auto back1=st.back(), back2=*prev(st.end(), 2);
return (back1-back2).toLeft(u-back1)<=0;
};
for(const Point &u:p)
{
while(st.size()>1&&check(st, u)) st.pop_back();
st.push_back(u);
}
size_t k=st.size();
p.pop_back();
reverse(p.begin(), p.end());
for(const Point &u:p)
{
while(st.size()>k&&check(st, u)) st.pop_back();
st.push_back(u);
}
st.pop_back();
return st;
}
vector<Point> convexHull2(vector<Point> p)
{
vector<Point> st;
if(p.empty()) return st;
sort(p.begin(), p.end());
reverse(p);
const auto check=[](const vector<Point> &st, const Point &u)
{
const auto back1=st.back(), back2=*prev(st.end(), 2);
return (back1-back2).toLeft(u-back1)<=0;
};
for(const Point &u:p)
{
while(st.size()>1&&check(st, u)) st.pop_back();
st.push_back(u);
}
size_t k=st.size();
p.pop_back();
reverse(p.begin(), p.end());
for(const Point &u:p)
{
while(st.size()>k&&check(st, u)) st.pop_back();
st.push_back(u);
}
st.pop_back();
return st;
}
bool preCheck(const vector<Point> &poly)
{
int n=poly.size();
for(int i=0; i<n; i++)
{
int u=i;
int v=(i+1)%n;
int w=(i+2)%n;
Vect v1(poly[u], poly[v]);
Vect v2(poly[v], poly[w]);
if(v1.toLeft(v2)==0)
{
return false;
}
}
return true;
}
bool compare(const vector<Point> &poly, const vector<Point> &convex)
{
auto it=find(poly.begin(), poly.end(), convex.front());
if(it==poly.end())return false;
if(it==poly.begin())it++;
vector<Point>s1(poly.begin(), it);
vector<Point>s2(it, poly.end());
vector<Point>r1=s1;
vector<Point>r2=s2;
reverse(r1);
reverse(r2);
vector<Point>now1(r1);
//dbg(r1);
//dbg(r2);
now1.insert(now1.end(), r2.begin(), r2.end());
vector<Point>now2(s2);
now2.insert(now2.end(), s1.begin(), s1.end());
//dbg(now1);
//dbg(now2);
return now1==convex||now2==convex;
}
int main()//MARK: main
{
#ifndef xxx
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#endif
cout<<fixed<<setprecision(10);
int n;
cin>>n;
vector<Point>poly(n);
for(int i=1; i<=n; i++)
{
poly[i-1].read();
}
auto convex1=convexHull1(poly);
auto convex2=convexHull2(poly);
//dbg(convex1);
//dbg(convex2);
bool flag=preCheck(poly)&&(compare(poly, convex1)||compare(poly, convex2));
cout<<(flag?"Yes":"No")<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3688kb
input:
3 0 0 1 0 0 1
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
4 0 0 0 1 1 1 1 0
output:
Yes
result:
ok answer is YES
Test #3:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
4 0 0 0 3 1 2 1 1
output:
Yes
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
3 0 0 0 0 0 0
output:
No
result:
ok answer is NO
Test #5:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 1 0 4 1 0 1 2 0 3 2
output:
No
result:
ok answer is NO
Test #6:
score: 0
Accepted
time: 0ms
memory: 3912kb
input:
5 0 0 1000000000 0 1000000000 500000000 1000000000 1000000000 0 1000000000
output:
No
result:
ok answer is NO
Test #7:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
5 0 0 1000000000 0 1000000000 499999999 1000000000 1000000000 0 1000000000
output:
No
result:
ok answer is NO
Test #8:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
5 0 0 999999999 0 1000000000 50000000 999999999 1000000000 0 1000000000
output:
Yes
result:
ok answer is YES
Test #9:
score: 0
Accepted
time: 31ms
memory: 17824kb
input:
128312 5578014 410408218 5585076 410404717 5588011 410403262 5588473 410403033 5589740 410402405 5593295 410400643 5593751 410400417 5597248 410398684 5598935 410397848 5600618 410397014 5605185 410394751 5610514 410392111 5614281 410390245 5617263 410388768 5621142 410386847 5630840 410382045 56310...
output:
Yes
result:
ok answer is YES
Test #10:
score: -100
Wrong Answer
time: 37ms
memory: 19216kb
input:
128086 149550602 509469827 149551059 509465022 149551336 509462107 149551964 509455497 149552572 509449094 149553350 509440895 149553656 509437667 149554161 509432339 149554254 509431357 149554545 509428284 149555017 509423299 149555366 509419611 149555842 509414580 149556382 509408867 149556564 509...
output:
No
result:
wrong answer expected YES, found NO