Submission #1297981

#TimeUsernameProblemLanguageResultExecution timeMemory
1297981huyngodzzPlanine (COCI21_planine)C++20
110 / 110
172 ms32428 KiB
///huynhocute123/// #include<bits/stdc++.h> using namespace std; #define S second #define F first #define pii pair<int,int> #define piii pair<int,pair<int,int>> #define pb push_back #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define REP(i, a, b) for(int i = b; i >= a; --i) #define ALL(v) v.begin(),v.end() #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin); #define out(name) if(fopen(name, "w")) freopen(name, "w", stdout); //random_device rd; //mt19937 rng(rd()); //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") //#define int long long const int MAX = 1e9+9; const long long MAXLL = 1e18+9; const double pi = 3.14159265358979323846; const double rad = 3.14159265358979323846 /180; bool minimize(int &u, int v){ if(v < u){ u = v; return 1; } return 0; } bool maximize(int &u, int v){ if(v > u){ u = v; return 1; } return 0; } bool maximizell(long long &u, long long v){ if(v > u){ u = v; return 1; } return 0; } bool minimizell(long long &u, long long v){ if(v < u){ u = v; return 1; } return 0; } const int mod = 1e9 + 7; inline int fastPow(int a, int n){ if(n == 0) return 1; int t = fastPow(a, n >> 1); t = 1ll * t * t % mod; if(n & 1) t = 1ll * t * a % mod; return t; } const int maxN = 1e6 + 999 ; struct Geo{ long long x ,y; Geo(){}; Geo(long long _x ,long long _y){ x = _x; y = _y; } void read(){ cin >> x >> y; } }; struct Line{ long long A ,B ,C; Line(long long _A ,long long _B ,long long _C){ A = _A; B = _B; C = _C; } }; Line build(const Geo& A ,const Geo& B){ Geo vec = Geo(B.x - A.x , B.y - A.y); Geo Nvec = Geo(vec.y ,-vec.x); return Line(Nvec.x , Nvec.y , -(1LL * Nvec.x * A.x + 1LL * Nvec.y * A.y)); } Geo heh[maxN]; int ccw(const Geo& A ,const Geo& B ,const Geo&C){ long long X = 1LL * (C.x - A.x) * (B.y - A.y) - 1LL*(B.x - A.x) * (C.y - A.y); if(X == 0)return 0; return( X > 0 ? 1 : -1); } int n, h; double kaka(const Geo& A ,const Geo& B){ Line AB = build(A ,B); // cout << AB.A << " "<< AB.B << " "<< AB.C << '\n'; if(AB.A == 0)return -MAXLL; return (1.0 * (-AB.B * h - AB.C))/ (1.0 * AB.A); } int L[maxN] , R[maxN]; inline void solve(){ cin >> n >> h; FOR(i, 1, n)heh[i].read(); vector<int>stk; FOR(i, 2, n){ while(stk.size() >= 2 && ccw(heh[stk[stk.size() - 2]], heh[stk.back()], heh[i]) <= 0){ // cout << stk[stk.size() - 2] << " "<< stk.back() << " "<< i << '\n'; stk.pop_back(); } if(stk.size())L[i] = stk.back(); else L[i] = i - 1; if( (i % 2) == 0 )stk.pb(i); } stk.clear(); REP(i, 1, n){ while(stk.size() >= 2 && ccw(heh[i], heh[stk.back()], heh[stk[stk.size() - 2]]) <= 0){ // cout << i << " "<< stk.back() << " "<< stk[stk.size() - 2] << '\n'; stk.pop_back(); } if(stk.size())R[i] = stk.back(); else R[i] = i + 1; if( (i % 2) == 0 )stk.pb(i); } // for(int i = 3; i <= n - 2 ;i += 2){ // cout << i << " " << L[i] << '\n'; // } int ans = 0; vector<pair<double ,double>>huh; for(int i = 3; i <= n - 2;i += 2)huh.pb({ kaka(heh[i] , heh[L[i]]) , kaka(heh[i] , heh[R[i]]) }); sort(ALL(huh)); for(int i = 0 ; i < huh.size();){ int j = i; double mx = huh[i].S; while(j < huh.size()){ if(huh[j].F > mx)break; mx = min(mx , huh[j].S); ++j; } i = j; ++ans; } cout << ans; // for(int i = 3; i <= n ; i += 2)cout << R[i] << '\n'; // Geo A(-4 ,3); // Geo B(0 ,4 ); // Geo C(2 ,2); // cout << ccw(A ,B ,C); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); #define NAME "task" if(fopen(NAME".inp", "r")){ freopen(NAME".inp", "r" ,stdin); // freopen(NAME".out", "w" ,stdout); } int tc = 1; // cin >> tc; while( tc-- )solve(); cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:156:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  156 |         freopen(NAME".inp", "r" ,stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...