답안 #1020180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020180 2024-07-11T16:25:39 Z avighna 이상한 기계 (APIO19_strange_device) C++17
100 / 100
634 ms 116020 KB
#include <bits/stdc++.h>

typedef long long ll;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  ll n, a, b;
  std::cin >> n >> a >> b;

  if (true) {
    // (2x % a, 0)
    // 2x % a == 0
    // if a is odd, then the cycle is of length a (the 2 will never
    // contribute)
    // if a is even, then the cycle of of length a/2
    ll cycle = a % 2 == 0 ? a / 2 : a;
    if (b != 0) {
      // w (B + 1) mod A = 0
      if (b / std::gcd(a, b + 1) >= (ll(1e18) + 1) / a) {
        cycle = ll(1e18) + 1;
      } else {
        cycle = a / std::gcd(a, b + 1) * b;
      }
    }
    std::vector<std::pair<ll, ll>> ranges;
    std::map<ll, ll> mp;
    while (n--) {
      ll l, r;
      std::cin >> l >> r;
      ll _l = l % cycle, _r = r % cycle;
      if (r - l + 1 >= cycle) {
        std::cout << cycle << "\n";
        return 0;
      }
      if (_l > _r) {
        ranges.push_back({_l, cycle - 1});
        ranges.push_back({0, _r});
      } else {
        ranges.push_back({_l, _r});
      }
    }
    for (auto &[l, r] : ranges) {
      mp[l] = std::max(mp[l], r);
    }
    ll right = 0;
    ll ans = 0;
    for (auto &i : mp) {
      if (i.second < right) {
        continue;
      }
      right = std::max(right, i.first);
      ans += i.second - right + 1;
      right = i.second + 1;
    }
    std::cout << ans << "\n";
    return 0;
  }

  std::set<std::pair<ll, ll>> st;
  while (n--) {
    ll l, r;
    std::cin >> l >> r;
    for (ll x = l; x <= r; ++x) {
      st.insert({(x + x / b) % a, x % b});
      //   std::cout << "(" << (x + x / b) % a << " " << x % b << "), ";
      //   std::cout << st.size() << "\n";
    }
  }
  std::cout << st.size() << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 7 ms 1504 KB Output is correct
3 Correct 7 ms 1504 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1572 KB Output is correct
17 Correct 63 ms 10924 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 241 ms 29916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 568 ms 97260 KB Output is correct
3 Correct 539 ms 97364 KB Output is correct
4 Correct 570 ms 97292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 568 ms 97260 KB Output is correct
3 Correct 539 ms 97364 KB Output is correct
4 Correct 570 ms 97292 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 551 ms 115692 KB Output is correct
7 Correct 541 ms 115724 KB Output is correct
8 Correct 527 ms 115748 KB Output is correct
9 Correct 584 ms 116020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 568 ms 97260 KB Output is correct
3 Correct 539 ms 97364 KB Output is correct
4 Correct 570 ms 97292 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 38 ms 10084 KB Output is correct
7 Correct 42 ms 11772 KB Output is correct
8 Correct 40 ms 11960 KB Output is correct
9 Correct 65 ms 11784 KB Output is correct
10 Correct 52 ms 11972 KB Output is correct
11 Correct 38 ms 11832 KB Output is correct
12 Correct 41 ms 11808 KB Output is correct
13 Correct 51 ms 11972 KB Output is correct
14 Correct 47 ms 11828 KB Output is correct
15 Correct 49 ms 11980 KB Output is correct
16 Correct 52 ms 11764 KB Output is correct
17 Correct 55 ms 11992 KB Output is correct
18 Correct 559 ms 115900 KB Output is correct
19 Correct 505 ms 115840 KB Output is correct
20 Correct 575 ms 115764 KB Output is correct
21 Correct 52 ms 11976 KB Output is correct
22 Correct 47 ms 11972 KB Output is correct
23 Correct 79 ms 20096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 48 ms 10184 KB Output is correct
3 Correct 56 ms 10276 KB Output is correct
4 Correct 550 ms 115824 KB Output is correct
5 Correct 47 ms 11848 KB Output is correct
6 Correct 72 ms 11972 KB Output is correct
7 Correct 69 ms 11972 KB Output is correct
8 Correct 70 ms 11976 KB Output is correct
9 Correct 54 ms 11972 KB Output is correct
10 Correct 42 ms 11976 KB Output is correct
11 Correct 49 ms 11844 KB Output is correct
12 Correct 44 ms 11912 KB Output is correct
13 Correct 61 ms 12236 KB Output is correct
14 Correct 634 ms 115884 KB Output is correct
15 Correct 40 ms 11984 KB Output is correct
16 Correct 517 ms 115876 KB Output is correct
17 Correct 500 ms 115768 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 7 ms 1504 KB Output is correct
3 Correct 7 ms 1504 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1572 KB Output is correct
17 Correct 63 ms 10924 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 452 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 241 ms 29916 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 568 ms 97260 KB Output is correct
31 Correct 539 ms 97364 KB Output is correct
32 Correct 570 ms 97292 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 551 ms 115692 KB Output is correct
35 Correct 541 ms 115724 KB Output is correct
36 Correct 527 ms 115748 KB Output is correct
37 Correct 584 ms 116020 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 38 ms 10084 KB Output is correct
40 Correct 42 ms 11772 KB Output is correct
41 Correct 40 ms 11960 KB Output is correct
42 Correct 65 ms 11784 KB Output is correct
43 Correct 52 ms 11972 KB Output is correct
44 Correct 38 ms 11832 KB Output is correct
45 Correct 41 ms 11808 KB Output is correct
46 Correct 51 ms 11972 KB Output is correct
47 Correct 47 ms 11828 KB Output is correct
48 Correct 49 ms 11980 KB Output is correct
49 Correct 52 ms 11764 KB Output is correct
50 Correct 55 ms 11992 KB Output is correct
51 Correct 559 ms 115900 KB Output is correct
52 Correct 505 ms 115840 KB Output is correct
53 Correct 575 ms 115764 KB Output is correct
54 Correct 52 ms 11976 KB Output is correct
55 Correct 47 ms 11972 KB Output is correct
56 Correct 79 ms 20096 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 48 ms 10184 KB Output is correct
59 Correct 56 ms 10276 KB Output is correct
60 Correct 550 ms 115824 KB Output is correct
61 Correct 47 ms 11848 KB Output is correct
62 Correct 72 ms 11972 KB Output is correct
63 Correct 69 ms 11972 KB Output is correct
64 Correct 70 ms 11976 KB Output is correct
65 Correct 54 ms 11972 KB Output is correct
66 Correct 42 ms 11976 KB Output is correct
67 Correct 49 ms 11844 KB Output is correct
68 Correct 44 ms 11912 KB Output is correct
69 Correct 61 ms 12236 KB Output is correct
70 Correct 634 ms 115884 KB Output is correct
71 Correct 40 ms 11984 KB Output is correct
72 Correct 517 ms 115876 KB Output is correct
73 Correct 500 ms 115768 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 344 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 4 ms 1504 KB Output is correct
80 Correct 566 ms 115880 KB Output is correct
81 Correct 599 ms 115900 KB Output is correct
82 Correct 611 ms 115868 KB Output is correct
83 Correct 577 ms 115868 KB Output is correct
84 Correct 622 ms 115792 KB Output is correct
85 Correct 544 ms 115800 KB Output is correct
86 Correct 81 ms 18448 KB Output is correct
87 Correct 0 ms 348 KB Output is correct