# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
213008 | 2020-03-24T18:34:09 Z | arman_ferdous | 이상한 기계 (APIO19_strange_device) | C++17 | 577 ms | 21608 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 ll oo = 2e18; vector<pair<ll,ll>> interval; int main () { int n; ll A, B; scanf("%d %lld %lld", &n, &A, &B); int inf = 0, all = 0; ll sum = 0; ll g = __gcd(A, B + 1); ll K = A / g; ll T = K * B; if(K > oo / B) inf = 1; while(n--) { ll l, r; scanf("%lld %lld", &l, &r); if(r - l + 1 >= T) { all = 1; break; } 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(all) printf("%lld\n", T); else if(inf) printf("%lld\n", sum); else { ll ans = 0; sort(interval.begin(), interval.end()); for(int i = 0; i < (int)interval.size(); i++) { ans += interval[i].second - interval[i].first + 1; if(i) ans -= max(interval[i - 1].second - interval[i].first + 1, 0ll); } printf("%lld\n", ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Incorrect | 10 ms | 1152 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 4 ms | 256 KB | Output is correct |
5 | Incorrect | 4 ms | 256 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Incorrect | 5 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 527 ms | 21592 KB | Output is correct |
3 | Correct | 515 ms | 21520 KB | Output is correct |
4 | Correct | 508 ms | 21456 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 527 ms | 21592 KB | Output is correct |
3 | Correct | 515 ms | 21520 KB | Output is correct |
4 | Correct | 508 ms | 21456 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 508 ms | 21448 KB | Output is correct |
7 | Correct | 517 ms | 21456 KB | Output is correct |
8 | Correct | 497 ms | 21456 KB | Output is correct |
9 | Correct | 556 ms | 21608 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 527 ms | 21592 KB | Output is correct |
3 | Correct | 515 ms | 21520 KB | Output is correct |
4 | Correct | 508 ms | 21456 KB | Output is correct |
5 | Correct | 4 ms | 256 KB | Output is correct |
6 | Correct | 56 ms | 5736 KB | Output is correct |
7 | Correct | 60 ms | 5736 KB | Output is correct |
8 | Correct | 53 ms | 5732 KB | Output is correct |
9 | Correct | 57 ms | 5732 KB | Output is correct |
10 | Correct | 58 ms | 5732 KB | Output is correct |
11 | Correct | 57 ms | 5736 KB | Output is correct |
12 | Correct | 56 ms | 5736 KB | Output is correct |
13 | Correct | 62 ms | 5736 KB | Output is correct |
14 | Correct | 58 ms | 5728 KB | Output is correct |
15 | Incorrect | 63 ms | 5732 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 67 ms | 5876 KB | Output is correct |
3 | Correct | 61 ms | 5732 KB | Output is correct |
4 | Correct | 577 ms | 21456 KB | Output is correct |
5 | Correct | 57 ms | 5736 KB | Output is correct |
6 | Correct | 56 ms | 5732 KB | Output is correct |
7 | Correct | 59 ms | 5736 KB | Output is correct |
8 | Correct | 59 ms | 5736 KB | Output is correct |
9 | Correct | 55 ms | 5736 KB | Output is correct |
10 | Correct | 57 ms | 5728 KB | Output is correct |
11 | Correct | 65 ms | 6016 KB | Output is correct |
12 | Correct | 53 ms | 5736 KB | Output is correct |
13 | Correct | 60 ms | 5732 KB | Output is correct |
14 | Incorrect | 570 ms | 21436 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Incorrect | 10 ms | 1152 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |