Submission #367292

#TimeUsernameProblemLanguageResultExecution timeMemory
367292MrRobot_28Planine (COCI21_planine)C++17
110 / 110
682 ms88388 KiB
#include<bits/stdc++.h> using namespace std; #define X first #define Y second #define int long long int crossproduct(pair <int, int> a, pair <int, int> b, pair <int, int> c) { return (b.X- a.X) * (c.Y - a.Y) - (b.Y - a.Y) * (c.X - a.X); } int n, h; vector <pair <int, int> > funct(vector <pair <int, int> > x) { vector <pair <int, int> > res(n / 2 - 1); vector <pair <int, int> > st; for(int i = 1; i < n - 1; i++) { while(st.size() > 1 && crossproduct(st[st.size() - 2], st.back(), x[i]) >= 0) { st.pop_back(); } st.push_back(x[i]); if(!(i & 1)) { auto [x1, y1] = st.rbegin()[0]; auto [x2, y2] = st.rbegin()[1]; /*int x1 = st[st.size() - 2].X; int y1 = st[st.size() - 2].Y; int x2 = x[i].X; int y2 = x[i].Y;*/ int x0 = (x1 - x2) * (h - y2) + x2 * (y1 - y2); int y0 = y1 - y2; // cout << st.size() << "\n"; res[i / 2 - 1] = {x0, y1 - y2}; } } return res; } bool cmp(pair <pair <int, int>, pair <int, int> > a, pair <pair <int, int>, pair <int, int> > b) { if(a.X.X * b.X.Y == a.X.Y * b.X.X) { return a.Y.X < b.Y.X; } return a.X.X * b.X.Y < a.X.Y * b.X.X; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> h; vector <pair <int, int> > x(n); for(int i = 0; i < n; i++) { cin >> x[i].X >> x[i].Y; } vector <pair <int, int> > a = funct(x); reverse(x.begin(), x.end()); for(int i = 0; i < n; i++) { x[i].X *= -1; } vector <pair <int, int> > b = funct(x); reverse(b.begin(), b.end()); for(int i = 0; i < b.size(); i++) { b[i].X *= -1; } int ans = 0; vector <pair <pair <int, int>, pair <int, int> > > scan; for(int i = 0; i < n / 2 - 1; i++) { scan.push_back({a[i], {-1, i}}); scan.push_back({b[i], {1, i}}); } sort(scan.begin(), scan.end(), cmp); set <int> s; for(int i = 0; i < scan.size(); i++) { int t = scan[i].Y.X; if(t == -1) { s.insert(scan[i].Y.Y); } else if(s.find(scan[i].Y.Y) != s.end()) { ans++; s.clear(); } } cout << ans; return 0; }

Compilation message (stderr)

Main.cpp: In function 'std::vector<std::pair<long long int, long long int> > funct(std::vector<std::pair<long long int, long long int> >)':
Main.cpp:31:17: warning: unused variable 'y0' [-Wunused-variable]
   31 |             int y0 = y1 - y2;
      |                 ^~
Main.cpp: In function 'int main()':
Main.cpp:65:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i = 0; i < b.size(); i++)
      |                    ~~^~~~~~~~~~
Main.cpp:78:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i = 0; i < scan.size(); i++)
      |                    ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...