제출 #254777

#제출 시각아이디문제언어결과실행 시간메모리
254777MarcoMeijerTriangles (CEOI18_tri)C++14
100 / 100
48 ms4344 KiB
#include <bits/stdc++.h> #include "trilib.h" using namespace std; // macros typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define FOR(a,b) for(auto& a : b) #define all(a) a.begin(), a.end() #define INF 1e9 #define EPS 1e-9 #define pb push_back #define popb pop_back #define fi first #define se second #define sz size() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // input template<class T> void IN(T& x) {cin >> x;} template<class H, class... T> void IN(H& h, T&... t) {IN(h); IN(t...); } // output template<class T1, class T2> void OUT(const pair<T1,T2>& x); template<class T> void OUT(const T& x) {cout << x;} template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); } template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi," ",x.se);} template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); } //===================// // Added libraries // //===================// //===================// //end added libraries// //===================// void program(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); program(); } //===================// // begin program // //===================// const int MX = 50000; int n, m; int SHUF[MX]; bool cw(int x, int y, int z) { return is_clockwise(SHUF[x],SHUF[y],SHUF[z]); } bool ccw(int x, int y, int z) { return !is_clockwise(SHUF[x],SHUF[y],SHUF[z]); } int MEX(int x, int y) { RE1(i,3) if(x != i && y != i) return i; } int origin; int S[2][MX], C[2][MX], N[2], M[2]; set<int> onSide[2]; int ST[2][MX], O[2]; int s1, s2; void program() { n = get_n(); RE1(i,n) SHUF[i] = i; shuffle(SHUF+1,SHUF+n+1,rng); if(n == 3) { give_answer(3); return; } // create two halves s1 = 1; s2 = 2; REI(j,3,n) onSide[cw(s1,s2,j)].insert(j); RE(i,2) { // i == 0 left side of 1->2, i == 1 right side of 1->2 onSide[i].insert(s1); onSide[i].insert(s2); origin = i+1; N[i] = 0; FOR(j,onSide[i]) S[i][N[i]++] = j; RE(j,N[i]) if(S[i][j] == origin) swap(S[i][j], S[i][0]); sort(S[i]+1,S[i]+N[i],[](int i, int j) { return ccw(origin, i, j); }); M[i]=0; C[i][M[i]++] = S[i][N[i]-1], C[i][M[i]++] = S[i][0]; int j=1; if(N[i] != 2) { while(j < N[i]) { if(ccw(C[i][M[i]-2],C[i][M[i]-1],S[i][j])) C[i][M[i]++] = S[i][j++]; else M[i]--; } } else { C[i][M[i]++] = S[i][1]; } } // merge two halves int answer = M[0]+M[1]-2-2; RE(h,2) { RE(i,2) O[i]=0; REP(j,2,M[ h]) ST[ h][O[ h]++] = C[ h][j]; REP(j,2,M[!h]) ST[!h][O[!h]++] = C[!h][j]; reverse(ST[h], ST[h]+O[h]); int c[2]; RE(i,2) c[i]=0; while((O[h]-c[h]) && (O[!h]-c[!h])) { if(O[h]-c[h] >= 2) { if(cw(ST[h][c[h]+1],ST[h][c[h]],ST[!h][c[!h]])) { answer--; c[h]++; continue; } } if(O[!h]-c[!h] >= 2) { if(ccw(ST[!h][c[!h]+1],ST[!h][c[!h]],ST[h][c[h]])) { answer--; c[!h]++; continue; } } break; } } give_answer(answer); }

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

tri.cpp: In function 'int MEX(int, int)':
tri.cpp:77: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...