Submission #1019351

# Submission time Handle Problem Language Result Execution time Memory
1019351 2024-07-10T18:10:07 Z avighna Strange Device (APIO19_strange_device) C++17
0 / 100
5000 ms 524288 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 (b == 1) {
    // (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;
    std::map<ll, ll> mp;
    while (n--) {
      ll l, r;
      std::cin >> l >> r;
      if (l != r && l % cycle == r % cycle) {
        l %= cycle, r = cycle - 1;
      } else {
        l %= cycle, r %= cycle;
      }
      mp[l] = std::max(mp[l], r);
    }
    ll right = 0;
    ll ans = 0;
    for (auto &i : mp) {
      if (i.second < right) {
        continue;
      }
      ans += i.second - right + 1;
      right = i.second;
    }
    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 << st.size() << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 28 ms 12636 KB Output is correct
3 Correct 41 ms 18256 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 5 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1722 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 80 ms 32336 KB Output is correct
3 Correct 90 ms 32184 KB Output is correct
4 Correct 70 ms 30616 KB Output is correct
5 Execution timed out 5046 ms 62596 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Incorrect 497 ms 99924 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Incorrect 497 ms 99924 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Incorrect 497 ms 99924 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1022 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 28 ms 12636 KB Output is correct
3 Correct 41 ms 18256 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 5 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -