Submission #239411

#TimeUsernameProblemLanguageResultExecution timeMemory
239411NucleistTriangles (CEOI18_tri)C++14
55 / 100
1323 ms262148 KiB
#include <bits/stdc++.h> 
#include "trilib.h"
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int k[40001];
map<pair<dos,ll>,bool>g;
bool ask(ll x,ll y,ll z){
  if(g.find({{x,y},z})!=g.end())return g[{{x,y},z}];
  ll f=is_clockwise(x+1,y+1,z+1);
  g[{{x,y},z}]=f;
  return f;
}
ll finfirsti(ve k){
  for (ll i = 0; i < k.size(); ++i)
  {
    bool ka=1;
    ll cur=i;
    ll nex=(i+1)%k.size();
    for (ll j = 0; j < k.size(); ++j)
    {
      if(j!=cur && j!=nex){
        ll yo=ask(cur,nex,j);
        if(yo){
          nex=j;
        }
      }
    }
    for (ll j = 0; j < k.size(); ++j)
    {
      if(j!=cur && j!=nex){
        ll yo=ask(cur,nex,j);
        if(yo){
          ka=0;break;
        }
      }
    }
    if(ka)return i;
  }
}
ll a;
int compare(const void * va, const void * vi) 
{ 
   ll v1=(*(int*)va);
   ll v2=(*(int*)vi);
   ll o = ask(a, v1, v2);
   o=1-o;
   o++;
   return (o == 2)? -1: 1; 
}
ll nextToTop(stack<ll>sa){
  sa.pop();
  return sa.top();
}
int main()
{
  flash;
  ll n=get_n();
  ve cur,cu,con;
  for (ll i = 0; i < n; ++i)
  {
    cur.pb(i);
  }
  //debug(1)
  a=finfirsti(cur);
  //debug(1)
  for (ll i = 0; i < n; ++i)
  {
    if(i!=a)cu.pb(i);
  }
  for (int i = 0; i < cu.size(); ++i)
  {
  	k[i]=cu[i];
  }
  if(n==3){
    give_answer(3);
  }
  else{
    qsort(k,n-1,sizeof(int),compare);
    con.pb(a);
    for (int i = 0; i < n-1; ++i)
    {
    	con.pb(k[i]);
    }
    stack<ll> S; 
    S.push(con[0]); 
    S.push(con[1]); 
    S.push(con[2]); 
    //debug(con[0])
    //debug(con[1])
    //debug(con[2])
    for (ll i = 3; i < n; i++) 
    {
      //debug(con[i])
      //debug(ask(nextToTop(S), S.top(), con[i]))
      while (sz(S)>1 && (1-ask(nextToTop(S), S.top(), con[i])+1) != 2) 
	     {
	     	//debug(S.top())
	     	S.pop();
	     }
      S.push(con[i]); 
    } 
    give_answer(S.size());
  }
  return 0;
}
//code the AC sol !
// BS/queue/map

Compilation message (stderr)

tri.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
tri.cpp:6:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
tri.cpp: In function 'long long int finfirsti(std::vector<long long int>)':
tri.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (ll i = 0; i < k.size(); ++i)
                  ~~^~~~~~~~~~
tri.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (ll j = 0; j < k.size(); ++j)
                    ~~^~~~~~~~~~
tri.cpp:54:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (ll j = 0; j < k.size(); ++j)
                    ~~^~~~~~~~~~
tri.cpp: In function 'int main()':
tri.cpp:96:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < cu.size(); ++i)
                   ~~^~~~~~~~~~~
tri.cpp: In function 'void setIO(std::__cxx11::string)':
tri.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".in").c_str(),"r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tri.cpp:29:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".out").c_str(),"w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tri.cpp: In function 'long long int finfirsti(std::vector<long long int>)':
tri.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...