# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
213052 | 2020-03-24T19:51:25 Z | arman_ferdous | 이상한 기계 (APIO19_strange_device) | C++17 | 5 ms | 512 KB |
/* at time = 0, (x, y) = (0, 0) * we need to find minimum t > 0, such that (x, y) = 0 again ie. the cycle period. * now, y = 0 = t % B => t = K * B (for some integer K) * putting t in x's eqn and simplifying gives us a nice formula * K * (B + 1) % A = 0 * from here it is easy to find K's value. * answering queries are just merging intervals */ #include <bits/stdc++.h> using namespace std; using ll = long long; const double oo = 1e19; vector<pair<ll,ll>> interval; int main () { int n; ll A, B; scanf("%d %lld %lld", &n, &A, &B); int inf = 0; ll sum = 0; ll g = __gcd(A, B + 1); ll K = A / g; ll T = K * B; if(K * 1.0 > oo / B * 1.0) inf = 1; while(n--) { ll l, r; scanf("%lld %lld", &l, &r); if(r - l + 1 >= T) { assert(1==2); printf("%lld\n", T); return 0; } sum += r - l + 1; ll le = l % T; ll ri = r % T; if(le <= ri) { interval.push_back({le, ri}); } else { interval.push_back({0, ri}); interval.push_back({le, T - 1}); } } if(inf) printf("%lld\n", sum); else { ll ans = 0, ptr = -1; sort(interval.begin(), interval.end()); for(int i = 0; i < (int)interval.size(); i++) { if(ptr < interval[i].first) { ans += interval[i].second - interval[i].first + 1; ptr = interval[i].second; } else { ans += max(0ll, interval[i].second - ptr); ptr = max(ptr, interval[i].second); } } printf("%lld\n", ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |