# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
213051 | 2020-03-24T19:48:28 Z | arman_ferdous | 이상한 기계 (APIO19_strange_device) | C++17 | 5000 ms | 524292 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) { 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); set<ll> st; for(auto it : interval) { for(ll i = it.first; i <= it.second; i++) st.insert(i); } printf("%d\n", (int)st.size()); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 41 ms | 9588 KB | Output is correct |
3 | Correct | 66 ms | 14068 KB | Output is correct |
4 | Correct | 6 ms | 768 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 10 ms | 1024 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 512 KB | Output is correct |
14 | Correct | 5 ms | 512 KB | Output is correct |
15 | Correct | 35 ms | 5368 KB | Output is correct |
16 | Correct | 27 ms | 5748 KB | Output is correct |
17 | Correct | 71 ms | 10340 KB | Output is correct |
18 | Incorrect | 5 ms | 384 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Runtime error | 4857 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 98 ms | 24312 KB | Output is correct |
3 | Correct | 95 ms | 24184 KB | Output is correct |
4 | Correct | 98 ms | 23160 KB | Output is correct |
5 | Execution timed out | 5102 ms | 87868 KB | Time limit exceeded |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 643 ms | 63036 KB | Output is correct |
3 | Runtime error | 2649 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 643 ms | 63036 KB | Output is correct |
3 | Runtime error | 2649 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 643 ms | 63036 KB | Output is correct |
3 | Runtime error | 2649 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Runtime error | 2242 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 41 ms | 9588 KB | Output is correct |
3 | Correct | 66 ms | 14068 KB | Output is correct |
4 | Correct | 6 ms | 768 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 10 ms | 1024 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 512 KB | Output is correct |
14 | Correct | 5 ms | 512 KB | Output is correct |
15 | Correct | 35 ms | 5368 KB | Output is correct |
16 | Correct | 27 ms | 5748 KB | Output is correct |
17 | Correct | 71 ms | 10340 KB | Output is correct |
18 | Incorrect | 5 ms | 384 KB | Output isn't correct |