Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <algorithm>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <string>
- #include <set>
- #include <cmath>
- #include <map>
- #include <unordered_map>
- #include <numeric>
- #include <random>
- #include <memory>
- #include <chrono>
- #include <iterator>
- #include <functional>
- #include <unordered_set>
- #include <cassert>
- #ifdef LOCAL
- #include "debug.h"
- #else
- #define debug(x...)
- #endif
- //#pragma GCC optimize("Ofast")
- //#define int ll
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair <int, int> pii;
- #define mp make_pair
- #define pb push_back
- #define sz(x) int((x).size())
- #ifndef LOCAL
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- #else
- mt19937 rng(228);
- #endif
- const int N = 2e3 + 7;
- const int inf = INT_MAX / 2;
- const ll INF = LLONG_MAX / 3;
- const int MOD = 1e9 + 7;
- const double eps = 1e-6;
- const string cars[] = {"🚗", "🚕", "🚙"};
- signed main() {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- cout << fixed << setprecision(9);
- ios::sync_with_stdio(false);
- cin.tie();
- cout.tie();
- int n;
- cin >> n;
- int r = n;
- vector < pii > a;
- for (int i = 0; i < n; i++) {
- int h, m, s;
- cin >> h >> m >> s;
- int start = s + m * 60 + h * 3600;
- cin >> h >> m >> s;
- int finish = s + m * 60 + h * 3600;
- if (start == finish) {
- r--;
- }
- else {
- if (start > finish) {
- a.push_back({ start, 1 });
- a.push_back({ 60 * 60 * 24, -1 });
- a.push_back({ 0, 1 });
- a.push_back({ finish, -1 });
- }
- else {
- a.push_back({ start, 1 });
- a.push_back({ finish, -1 });
- }
- }
- }
- sort(a.begin(), a.end(), [](auto x, auto y) {
- if (x.first != y.first) {
- return x.first < y.first;
- }
- return x.second > y.second;
- });
- int b = 0, ans = 0;
- for (int i = 0; i < sz(a); i++) {
- b += a[i].second;
- if (b == r) {
- ans += a[i + 1].first - a[i].first;
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement