Submission #283187

# Submission time Handle Problem Language Result Execution time Memory
283187 2020-08-25T11:00:40 Z WLZ Strange Device (APIO19_strange_device) C++14
100 / 100
563 ms 53584 KB
#include <bits/stdc++.h>
using namespace std;

long long gcd(long long a, long long b) {
  while (b > 0) {
    swap(a, b);
    b %= a;
  }
  return a;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long a, b;
  cin >> n >> a >> b;
  long long md = (long long) 1e18 + 1;
  a /= gcd(a, b + 1);
  if (a <= numeric_limits<long long>::max() / b) {
    md = a * b;
  }
  vector< pair<long long, long long> > v;
  for (int i = 0; i < n; i++) {
    long long l, r;
    cin >> l >> r;
    if (r - l + 1 >= md) {
      cout << md << '\n';
      return 0;
    }
    long long x = l % md, y = r % md;
    if (x <= y) {
      v.push_back({x, y});
    } else {
      v.push_back({x, md - 1});
      v.push_back({0, y});
    }
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  long long l = v[0].first, r = v[0].second;
  for (auto& p : v) {
    if (p.first > r) {
      ans += r - l + 1;
      l = p.first;
      r = p.second;
    } else {
      r = max(r, p.second);
    }
  }
  ans += r - l + 1;
  cout << ans << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1152 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 50 ms 4848 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 348 ms 16980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 538 ms 16980 KB Output is correct
3 Correct 460 ms 17228 KB Output is correct
4 Correct 439 ms 16980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 538 ms 16980 KB Output is correct
3 Correct 460 ms 17228 KB Output is correct
4 Correct 439 ms 16980 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 443 ms 17056 KB Output is correct
7 Correct 455 ms 17016 KB Output is correct
8 Correct 441 ms 16980 KB Output is correct
9 Correct 487 ms 17092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 538 ms 16980 KB Output is correct
3 Correct 460 ms 17228 KB Output is correct
4 Correct 439 ms 16980 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 45 ms 4856 KB Output is correct
7 Correct 48 ms 4856 KB Output is correct
8 Correct 47 ms 4848 KB Output is correct
9 Correct 46 ms 4848 KB Output is correct
10 Correct 45 ms 4848 KB Output is correct
11 Correct 47 ms 4848 KB Output is correct
12 Correct 49 ms 4856 KB Output is correct
13 Correct 48 ms 4848 KB Output is correct
14 Correct 45 ms 4848 KB Output is correct
15 Correct 50 ms 4848 KB Output is correct
16 Correct 49 ms 4848 KB Output is correct
17 Correct 46 ms 4848 KB Output is correct
18 Correct 460 ms 17088 KB Output is correct
19 Correct 447 ms 16980 KB Output is correct
20 Correct 526 ms 16980 KB Output is correct
21 Correct 49 ms 4720 KB Output is correct
22 Correct 46 ms 4720 KB Output is correct
23 Correct 141 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 48 ms 4728 KB Output is correct
3 Correct 49 ms 4720 KB Output is correct
4 Correct 534 ms 17124 KB Output is correct
5 Correct 47 ms 4592 KB Output is correct
6 Correct 48 ms 4592 KB Output is correct
7 Correct 48 ms 4592 KB Output is correct
8 Correct 49 ms 4592 KB Output is correct
9 Correct 49 ms 4600 KB Output is correct
10 Correct 49 ms 4600 KB Output is correct
11 Correct 48 ms 4592 KB Output is correct
12 Correct 43 ms 4592 KB Output is correct
13 Correct 48 ms 4588 KB Output is correct
14 Correct 492 ms 16980 KB Output is correct
15 Correct 48 ms 4464 KB Output is correct
16 Correct 449 ms 17080 KB Output is correct
17 Correct 444 ms 16980 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1152 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 50 ms 4848 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 348 ms 16980 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 538 ms 16980 KB Output is correct
31 Correct 460 ms 17228 KB Output is correct
32 Correct 439 ms 16980 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 443 ms 17056 KB Output is correct
35 Correct 455 ms 17016 KB Output is correct
36 Correct 441 ms 16980 KB Output is correct
37 Correct 487 ms 17092 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 45 ms 4856 KB Output is correct
40 Correct 48 ms 4856 KB Output is correct
41 Correct 47 ms 4848 KB Output is correct
42 Correct 46 ms 4848 KB Output is correct
43 Correct 45 ms 4848 KB Output is correct
44 Correct 47 ms 4848 KB Output is correct
45 Correct 49 ms 4856 KB Output is correct
46 Correct 48 ms 4848 KB Output is correct
47 Correct 45 ms 4848 KB Output is correct
48 Correct 50 ms 4848 KB Output is correct
49 Correct 49 ms 4848 KB Output is correct
50 Correct 46 ms 4848 KB Output is correct
51 Correct 460 ms 17088 KB Output is correct
52 Correct 447 ms 16980 KB Output is correct
53 Correct 526 ms 16980 KB Output is correct
54 Correct 49 ms 4720 KB Output is correct
55 Correct 46 ms 4720 KB Output is correct
56 Correct 141 ms 10844 KB Output is correct
57 Correct 0 ms 384 KB Output is correct
58 Correct 48 ms 4728 KB Output is correct
59 Correct 49 ms 4720 KB Output is correct
60 Correct 534 ms 17124 KB Output is correct
61 Correct 47 ms 4592 KB Output is correct
62 Correct 48 ms 4592 KB Output is correct
63 Correct 48 ms 4592 KB Output is correct
64 Correct 49 ms 4592 KB Output is correct
65 Correct 49 ms 4600 KB Output is correct
66 Correct 49 ms 4600 KB Output is correct
67 Correct 48 ms 4592 KB Output is correct
68 Correct 43 ms 4592 KB Output is correct
69 Correct 48 ms 4588 KB Output is correct
70 Correct 492 ms 16980 KB Output is correct
71 Correct 48 ms 4464 KB Output is correct
72 Correct 449 ms 17080 KB Output is correct
73 Correct 444 ms 16980 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 5 ms 1152 KB Output is correct
80 Correct 535 ms 53336 KB Output is correct
81 Correct 563 ms 53584 KB Output is correct
82 Correct 548 ms 53420 KB Output is correct
83 Correct 519 ms 53524 KB Output is correct
84 Correct 519 ms 53324 KB Output is correct
85 Correct 514 ms 53328 KB Output is correct
86 Correct 148 ms 18512 KB Output is correct
87 Correct 1 ms 384 KB Output is correct