# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
140579 | 2019-08-03T15:46:04 Z | luciocf | 이상한 기계 (APIO19_strange_device) | C++14 | 5000 ms | 524292 KB |
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; typedef long long ll; typedef pair<ll, ll> pii; int n; ll A, B; void solve_1(void) { ll l, r; scanf("%lld %lld", &l, &r); ll x = (r-l+1)/B; ll g = A/__gcd(B+1, A); if (x >= g) printf("%lld\n", B*g); else printf("%lld\n", r-l+1); } void solve_2(void) { set<ll> st; for (int i = 1; i <= n; i++) { ll l, r; scanf("%lld %lld", &l, &r); for (ll j = l; j <= r; j++) st.insert(j); } map<pair<ll, ll>, int> mp; int ans = 0; for (auto t: st) { ll x = (t + t/B)%A; ll y = t%B; if (!mp[{x, y}]) ans++; mp[{x, y}] = 1; } printf("%d\n", ans); } void solve_4(void) { vector<pii> V; if (A%2 == 0) A /= 2ll; bool ok = 0; for (int i = 1; i <= n; i++) { ll l, r; scanf("%lld %lld", &l, &r); if (r-l+1 >= A) { ok = 1; } else { if (l%A <= r%A) { V.push_back({l%A, r%A}); } else { V.push_back({l%A, A-1}); V.push_back({0, r%A}); } } } if (ok) { printf("%lld\n", A); return; } sort(V.begin(), V.end()); ll ans = V[0].ss-V[0].ff+1, last = V[0].ss; for (int i = 1; i < V.size(); i++) { ll l = V[i].ff, r = V[i].ss; if (l > last) { ans += r-l+1; last = r; } else { if (r > last) { ans += r-last; last = r; } } } printf("%lld\n", ans); } int main(void) { scanf("%d %lld %lld", &n, &A, &B); if (n == 1) { solve_1(); return 0; } if (B == 1) { solve_4(); return 0; } solve_2(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 167 ms | 21596 KB | Output is correct |
3 | Correct | 262 ms | 31508 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 504 KB | Output is correct |
7 | Correct | 4 ms | 632 KB | Output is correct |
8 | Correct | 4 ms | 632 KB | Output is correct |
9 | Correct | 36 ms | 3976 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 292 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 201 ms | 21340 KB | Output is correct |
16 | Correct | 93 ms | 11960 KB | Output is correct |
17 | Correct | 131 ms | 11428 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 420 KB | Output is correct |
2 | Correct | 523 ms | 62548 KB | Output is correct |
3 | Correct | 561 ms | 61736 KB | Output is correct |
4 | Correct | 546 ms | 59728 KB | Output is correct |
5 | Runtime error | 4672 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 583 ms | 16840 KB | Output is correct |
3 | Correct | 571 ms | 18976 KB | Output is correct |
4 | Correct | 548 ms | 19048 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 583 ms | 16840 KB | Output is correct |
3 | Correct | 571 ms | 18976 KB | Output is correct |
4 | Correct | 548 ms | 19048 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Runtime error | 4671 ms | 524288 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 583 ms | 16840 KB | Output is correct |
3 | Correct | 571 ms | 18976 KB | Output is correct |
4 | Correct | 548 ms | 19048 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 812 ms | 113672 KB | Output is correct |
7 | Runtime error | 4755 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Execution timed out | 5050 ms | 513372 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 167 ms | 21596 KB | Output is correct |
3 | Correct | 262 ms | 31508 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 504 KB | Output is correct |
7 | Correct | 4 ms | 632 KB | Output is correct |
8 | Correct | 4 ms | 632 KB | Output is correct |
9 | Correct | 36 ms | 3976 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 292 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 201 ms | 21340 KB | Output is correct |
16 | Correct | 93 ms | 11960 KB | Output is correct |
17 | Correct | 131 ms | 11428 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
19 | Correct | 2 ms | 256 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 256 KB | Output is correct |
22 | Correct | 2 ms | 256 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 420 KB | Output is correct |
25 | Correct | 523 ms | 62548 KB | Output is correct |
26 | Correct | 561 ms | 61736 KB | Output is correct |
27 | Correct | 546 ms | 59728 KB | Output is correct |
28 | Runtime error | 4672 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |