Submission #398439

#TimeUsernameProblemLanguageResultExecution timeMemory
398439AKikoStrange Device (APIO19_strange_device)C++17
0 / 100
1850 ms81164 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ss second #define ff first #define pb push_back #define pii pair<int, int> #define INF INT_MAX #define debug(n) cout << #n << " = " << n << "\n"; #define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll MOD = 1e9 + 7; int main() { ll n, A, B, T, K; cin >> n >> A >> B; K = A / __gcd(B + 1, A); T = K * B; map<ll, ll> m; for(int i = 0; i < n; i++) { ll l, r; cin >> l >> r; if(r - l + 1 >= T) { cout << T << "\n"; return 0; } if(r % T < l % T) { m[0]++; m[r % T + 1]--; m[l]++; m[T]--; } else { m[l % T]++; m[r % T + 1]--; } } ll prev = 0; vector<pair<ll, ll> > segments; for(auto el : m) { prev += el.ss; segments.pb({el.ff, prev}); } ll ans = 0; for(int i = 0; i < int(segments.size() - 1); i++) { if(segments[i].ss > 0){ ans += segments[i + 1].ff - segments[i].ff; } } cout << ans << "\n"; return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...