답안 #1020114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020114 2024-07-11T15:08:25 Z avighna 이상한 기계 (APIO19_strange_device) C++17
5 / 100
1755 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 (a <= b || 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;
    if (a <= b) {
      cycle = b / std::gcd(a + 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 0 ms 348 KB Output is correct
2 Incorrect 5 ms 1200 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 104 ms 32420 KB Output is correct
3 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 463 ms 115784 KB Output is correct
3 Correct 511 ms 115792 KB Output is correct
4 Correct 523 ms 115620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 463 ms 115784 KB Output is correct
3 Correct 511 ms 115792 KB Output is correct
4 Correct 523 ms 115620 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Runtime error 1755 ms 524288 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 463 ms 115784 KB Output is correct
3 Correct 511 ms 115792 KB Output is correct
4 Correct 523 ms 115620 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 148 ms 66388 KB Output is correct
7 Runtime error 1430 ms 524288 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 48 ms 11912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 5 ms 1200 KB Output isn't correct
3 Halted 0 ms 0 KB -