이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "trilib.h"
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int nn; int god;
map<int,bool> ma;
int hsh(int x, int y, int z)
{
return (x<<18)^(y<<9)^z;
}
bool ex(int x, int y, int z)
{
return (ma.find(hsh(x,y,z))!=ma.end());
}
bool is_cl(int x, int y, int z)
{
/*
if(ex(x,y,z)) return ma[hsh(x,y,z)];
if(ex(x,z,y)) return !ma[hsh(x,z,y)];
if(ex(y,x,z)) return !ma[hsh(y,x,z)];
if(ex(y,z,x)) return ma[hsh(y,z,x)];
if(ex(z,x,y)) return ma[hsh(z,x,y)];
if(ex(z,y,x)) return !ma[hsh(z,y,x)];
return (ma[hsh(x,y,z)] = is_clockwise(x+1,y+1,z+1));
*/
return is_clockwise(x+1,y+1,z+1);
}
bool cmp(int x, int y)
{
return is_cl(god,x,y);
}
int ans;
/*
int get_lowest(vi v)
{
if(v.size()<=1) return v[0];
random_shuffle(v.begin(),v.end());
int u = v[0];
vector<int> vec;
for(int i=1;i<v.size();i++)
{
vec.pb(v[i]);
}
god=u;
stable_sort(vec.begin(),vec.end(),cmp);
int id=int(vec.size());
for(int i=int(vec.size())-1;i>=0;i--)
{
if(is_cl(god,vec[i],vec[0]))
{
id=i;
}
else break;
}
if(id==int(vec.size())) return u;
int mid=int(v.size())/2;
if(id>=mid)
{
vi nw;
for(int i=id;i<v.size();i++)
{
nw.pb(v[i]);
}
return get_lowest(nw);
}
else
{
vi nw;
for(int i=0;i<id;i++)
{
nw.pb(v[i]);
}
return get_lowest(nw);
}
}
*/
bool check_properly(int u)
{
god=u;
vi U,D;
int x=0;
if(u==0) x=1;
for(int i=0;i<nn;i++)
{
if(i==u) continue;
if(i==x) continue;
if(!is_cl(god,x,i))
{
//cerr<<"CLOCKWISE "<<god<<' '<<x<<' '<<i<<'\n';
U.pb(i);
}
else
{
D.pb(i);
}
}
//cerr<<U.size()<<' '<<D.size()<<'\n';
if(U.empty()||D.empty()) return true;
int mxU=U[0]; int mxD=D[0];
for(int i=1;i<U.size();i++)
{
if(!is_cl(god,mxU,U[i]))
{
mxU=U[i];
}
}
for(int i=1;i<D.size();i++)
{
if(is_cl(god,mxD,D[i]))
{
mxD=D[i];
}
}
//cerr<<mxU<<' '<<mxD<<'\n';
if(is_cl(god,mxU,mxD)) return true;
return false;
}
void solve_init(int u)
{
vector<int> vec;
for(int i=0;i<nn;i++)
{
if(u!=i) vec.pb(i);
}
god=u;
stable_sort(vec.begin(),vec.end(),cmp);
if(is_cl(god,vec.back(),vec.front())) return ;
vector<int> S;
S.pb(u);
S.pb(vec[0]); S.pb(vec[1]);
for(int i=2;i<vec.size();i++)
{
int u=vec[i];
while(S.size()>=2&&!is_cl(S[int(S.size())-2], S[int(S.size())-1], u))
{
S.pop_back();
}
S.pb(u);
}
ans=min(ans,int(S.size()));
}
/*
const int C = 1200;
bool do_random_check(int u)
{
god=u;
for(int i=0;i<C/3;i++)
{
int j = rand()%nn;
int k = rand()%nn;
int l = rand()%nn;
while(j==k||k==l||l==j||j==u||k==u||l==u)
{
j=rand()%nn; k=rand()%nn; l=rand()%nn;
}
vi vec={j,k,l};
stable_sort(vec.begin(),vec.end(),cmp);
if(is_cl(god,vec[2],vec[0])) return false;
}
return true;
}
*/
int main()
{
srand(1912);
nn = get_n();
ans = nn;
vector<int> vertices;
for(int i=0;i<nn;i++) vertices.pb(i);
if(nn>15000)
{
for(int i=0;i<nn;i++)
{
if(nn>500&&i>=2) break;
solve_init(vertices[i]);
}
}
else if(nn<=3)
{
for(int i=0;i<nn;i++)
{
solve_init(vertices[i]);
}
}
else
{
int good=-1;
for(int i=0;i<nn;i++)
{
int v=vertices[i];
bool ok = check_properly(v);
if(ok)
{
good=v;
solve_init(v); break;
}
}
assert(good>=0);
}
give_answer(ans);
}
컴파일 시 표준 에러 (stderr) 메시지
tri.cpp: In function 'bool check_properly(int)':
tri.cpp:119:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<U.size();i++)
~^~~~~~~~~
tri.cpp:126:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<D.size();i++)
~^~~~~~~~~
tri.cpp: In function 'void solve_init(int)':
tri.cpp:151:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=2;i<vec.size();i++)
~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |