제출 #503685

#제출 시각아이디문제언어결과실행 시간메모리
503685andrei_boacaTriangles (CEOI18_tri)C++17
75 / 100
751 ms227752 KiB
#include <bits/stdc++.h> #include "trilib.h" //#include "trilib.c" using namespace std; mt19937 rng(time(NULL)); map<vector<int>,bool> f; set<int> border; vector<int> stiva,v; int root; bool use[40005]; int calls=0; bool notgood[40005]; bool isgood(int a,int b,int c) { vector<int> v; v.push_back(a); v.push_back(b); v.push_back(c); sort(v.begin(),v.end()); if(f.count(v)==0) { f[v]=is_clockwise(v[0],v[1],v[2]); calls++; assert(calls<=1e6); } bool ans=f[v]; int nr=0; if(a!=v[0]) nr++; if(b!=v[1]) nr++; if(c!=v[2]) nr++; if(nr%2==0&&nr>0) ans=!ans; return ans; } bool comp(int a, int b) { if(isgood(root,a,b)) return 1; return 0; } set<int> ok; int main() { int n; n=get_n(); int i=1; for(int i=1;i<=n;i++) ok.insert(i); while(border.empty()) { int good=2; int val=-1; use[i]=1; ok.erase(i); int j=1; for(j=1;j<=n;j++) if(notgood[j]==0&&i!=j) break; bool need=1; if(calls>500000) need=0; for(int k=1;k<=n;k++) if(k!=i&&k!=j&&notgood[k]==0) if(isgood(i,j,k)==need) j=k; for(int k=1;k<=n;k++) if(k!=i&&k!=j&&notgood[k]==0) if(isgood(i,j,k)==need) good=0; if(good) { border.insert(i); border.insert(j); break; } else { notgood[i]=1; i=j; if(use[i]) i=*prev(ok.end()); } } int j=*border.begin(); stiva.push_back(j); root=j; for(int i=1;i<=n;i++) if(i!=j) v.push_back(i); sort(v.begin(),v.end(),comp); stiva.push_back(v[0]); for(int i=1;i<v.size();i++) { int nod=v[i]; while(stiva.size()>=2) { int lg=stiva.size(); int b=stiva[lg-1]; int a=stiva[lg-2]; if(!isgood(a,b,nod)) stiva.pop_back(); else break; } stiva.push_back(nod); } int ans=stiva.size(); give_answer(ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

tri.cpp: In function 'int main()':
tri.cpp:55:17: warning: unused variable 'val' [-Wunused-variable]
   55 |             int val=-1;
      |                 ^~~
tri.cpp:95:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(int i=1;i<v.size();i++)
      |                 ~^~~~~~~~~
#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...