Advertisement
aayyk

Untitled

Nov 4th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <queue>
  7. #include <stack>
  8. #include <climits>
  9. #include <string>
  10. #include <set>
  11. #include <cmath>
  12. #include <map>
  13. #include <unordered_map>
  14. #include <numeric>
  15. #include <random>
  16. #include <memory>
  17. #include <chrono>
  18. #include <iterator>
  19. #include <functional>
  20. #include <unordered_set>
  21. #include <cassert>
  22. #ifdef LOCAL
  23. #include "debug.h"
  24. #else
  25. #define debug(x...)
  26. #endif
  27. //#pragma GCC optimize("Ofast")
  28. //#define int ll
  29.  
  30.  
  31.  
  32. using namespace std;
  33. typedef long long ll;
  34. typedef long double ld;
  35. typedef pair <int, int> pii;
  36. #define mp make_pair
  37. #define pb push_back
  38. #define sz(x) int((x).size())
  39.  
  40. #ifndef LOCAL
  41. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  42. #else
  43. mt19937 rng(228);
  44. #endif
  45.  
  46. const int N = 2e3 + 7;
  47. const int inf = INT_MAX / 2;
  48. const ll INF = LLONG_MAX / 3;
  49. const int MOD = 1e9 + 7;
  50. const double eps = 1e-6;
  51. const string cars[] = {"🚗", "🚕", "🚙"};
  52.  
  53.  
  54. signed main() {
  55. #ifdef LOCAL
  56.     freopen("input.txt", "r", stdin);
  57.     freopen("output.txt", "w", stdout);
  58. #endif
  59.     cout << fixed << setprecision(9);
  60.     ios::sync_with_stdio(false);
  61.     cin.tie();
  62.     cout.tie();
  63.  
  64.     int n;
  65.     cin >> n;
  66.     int r = n;
  67.  
  68.     vector < pii > a;
  69.  
  70.     for (int i = 0; i < n; i++) {
  71.         int h, m, s;
  72.         cin >> h >> m >> s;
  73.         int start = s + m * 60 + h * 3600;
  74.        
  75.         cin >> h >> m >> s;
  76.         int finish = s + m * 60 + h * 3600;
  77.  
  78.         if (start == finish) {
  79.             r--;
  80.         }
  81.         else {
  82.             if (start > finish) {
  83.                 a.push_back({ start, 1 });
  84.                 a.push_back({ 60 * 60 * 24, -1 });
  85.  
  86.                 a.push_back({ 0, 1 });
  87.                 a.push_back({ finish, -1 });
  88.             }
  89.             else {
  90.                 a.push_back({ start, 1 });
  91.                 a.push_back({ finish, -1 });
  92.             }
  93.  
  94.         }
  95.     }
  96.  
  97.     sort(a.begin(), a.end(), [](auto x, auto y) {
  98.         if (x.first != y.first) {
  99.             return x.first < y.first;
  100.         }
  101.         return x.second > y.second;
  102.     });
  103.    
  104.     int b = 0, ans = 0;
  105.     for (int i = 0; i < sz(a); i++) {
  106.         b += a[i].second;
  107.  
  108.         if (b == r) {
  109.             ans += a[i + 1].first - a[i].first;
  110.         }
  111.     }
  112.  
  113.     cout << ans;
  114.  
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement