Advertisement
Alex_tz307

USACO 2020 US Open Contest, Bronze Problem 2. Social Distancing II

Dec 7th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. // http://www.usaco.org/index.php?page=viewproblem2&cpid=1036
  2. #include <bits/stdc++.h>
  3. #define pi pair<int,int>
  4. #define x first
  5. #define ok second
  6. #define INF 0x3f3f3f3f
  7.  
  8. using namespace std;
  9.  
  10. ifstream fin("socdist2.in");
  11. ofstream fout("socdist2.out");
  12.  
  13. void min_self(int &a, int b) {
  14.     a = min(a, b);
  15. }
  16.  
  17. int main() {
  18.     int N;
  19.     fin >> N;
  20.     vector<pi> a(N);
  21.     for(int i = 0; i < N; ++i)
  22.         fin >> a[i].x >> a[i].ok;
  23.     sort(a.begin(), a.end());
  24.     int R = INF;
  25.     for(int i = 0; i < N; ++i)
  26.         if(i > 0 && a[i].ok != a[i - 1].ok)
  27.             min_self(R, a[i].x - a[i - 1].x);
  28.     --R;
  29.     int p = 0;
  30.     while(a[p].ok == 0)
  31.         ++p;
  32.     int ans = 1, last = a[p].x;
  33.     for(int i = p + 1; i < N; ++i)
  34.         if(a[i].ok == 1) {
  35.             if(a[i].x - last > R)
  36.                 ++ans;
  37.             last = a[i].x;
  38.         }
  39.     fout << ans;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement