답안 #283183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
283183 2020-08-25T10:59:15 Z WLZ 이상한 기계 (APIO19_strange_device) C++14
65 / 100
540 ms 53568 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;
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 0 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 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 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 52 ms 5740 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 351 ms 41396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 468 ms 53312 KB Output is correct
3 Correct 483 ms 53436 KB Output is correct
4 Correct 445 ms 53312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 468 ms 53312 KB Output is correct
3 Correct 483 ms 53436 KB Output is correct
4 Correct 445 ms 53312 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 470 ms 53312 KB Output is correct
7 Correct 459 ms 53312 KB Output is correct
8 Correct 449 ms 53316 KB Output is correct
9 Correct 501 ms 53444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 468 ms 53312 KB Output is correct
3 Correct 483 ms 53436 KB Output is correct
4 Correct 445 ms 53312 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 45 ms 5740 KB Output is correct
7 Correct 48 ms 5740 KB Output is correct
8 Correct 45 ms 5736 KB Output is correct
9 Correct 46 ms 5740 KB Output is correct
10 Correct 45 ms 5696 KB Output is correct
11 Correct 48 ms 5740 KB Output is correct
12 Correct 45 ms 5740 KB Output is correct
13 Correct 48 ms 5740 KB Output is correct
14 Correct 45 ms 5740 KB Output is correct
15 Correct 51 ms 5740 KB Output is correct
16 Correct 49 ms 5740 KB Output is correct
17 Correct 47 ms 5736 KB Output is correct
18 Correct 466 ms 53312 KB Output is correct
19 Correct 458 ms 53312 KB Output is correct
20 Correct 518 ms 53312 KB Output is correct
21 Correct 50 ms 5740 KB Output is correct
22 Correct 46 ms 5768 KB Output is correct
23 Correct 144 ms 18528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 50 ms 5868 KB Output is correct
3 Correct 48 ms 5740 KB Output is correct
4 Correct 540 ms 53344 KB Output is correct
5 Correct 49 ms 5868 KB Output is correct
6 Correct 50 ms 5736 KB Output is correct
7 Correct 48 ms 5740 KB Output is correct
8 Correct 49 ms 5740 KB Output is correct
9 Correct 48 ms 5728 KB Output is correct
10 Correct 51 ms 5740 KB Output is correct
11 Correct 49 ms 5716 KB Output is correct
12 Correct 43 ms 5740 KB Output is correct
13 Correct 48 ms 5736 KB Output is correct
14 Correct 513 ms 53568 KB Output is correct
15 Correct 48 ms 5736 KB Output is correct
16 Correct 455 ms 53312 KB Output is correct
17 Correct 458 ms 53300 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 0 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 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 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 52 ms 5740 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Incorrect 1 ms 384 KB Output isn't correct
21 Halted 0 ms 0 KB -