답안 #702841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702841 2023-02-25T08:49:26 Z veehz 이상한 기계 (APIO19_strange_device) C++17
100 / 100
2742 ms 209748 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

vector<ll> original;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  vector<pair<ll, ll>> v(n);
  for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;

  ll gc = __gcd(a, b + 1);
  bool smallEnough = (__int128_t(a) / gc * __int128_t(b) <= LONG_LONG_MAX);
  ll cy = smallEnough ? a / gc * b : 0;

  if (!smallEnough) {
    for (int i = 0; i < n; i++) {
      original.push_back(v[i].first);
      original.push_back(v[i].second);
      original.push_back(v[i].second + 1);
    }
  } else {
    for (int i = 0; i < n; i++) {
      original.push_back(v[i].first % cy);
      original.push_back(v[i].second % cy);
      original.push_back((v[i].second + 1) % cy);
    }
    original.push_back(0);
    original.push_back(cy - 1);
    original.push_back(cy);
  }

  sort(original.begin(), original.end());
  original.resize(unique(original.begin(), original.end()) - original.begin());
  map<ll, ll> mp;
  for (int i = 0; i < (int)original.size(); i++) mp[original[i]] = i;

  vector<int> pre(original.size() + 1);
  for (int i = 0; i < n; i++) {
    auto& p = v[i];
    ll l = p.first, r = p.second;
    if (smallEnough && r - l + 1 >= cy) {
      cerr << "FULL" << endl;
      cout << cy << endl;
      return 0;
    }

    auto add = [&](ll L, ll R) {
      pre[mp[L]]++;
      pre[mp[R + 1]]--;
    };

    if (smallEnough) {
      l %= cy;
      r %= cy;
      if (l > r) {
        add(l, cy - 1);
        add(0, r);
      } else {
        add(l, r);
      }
    } else {
      add(l, r);
    }
  }

  //   for (int i = 1; i < pre.size(); i++) pre[i] += pre[i - 1];
  int cur = 0;
  ll ans = 0;
  for (int i = 0; i < (int)pre.size() - 1; i++) {
    cur += pre[i];
    if (cur > 0) ans += original[i + 1] - original[i];
  }
  cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 19 ms 1996 KB Output is correct
3 Correct 20 ms 1968 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 18 ms 2000 KB Output is correct
17 Correct 186 ms 10924 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 975 ms 48824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1905 ms 105984 KB Output is correct
3 Correct 2299 ms 209596 KB Output is correct
4 Correct 2333 ms 209632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1905 ms 105984 KB Output is correct
3 Correct 2299 ms 209596 KB Output is correct
4 Correct 2333 ms 209632 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2301 ms 209652 KB Output is correct
7 Correct 1925 ms 143132 KB Output is correct
8 Correct 2359 ms 209652 KB Output is correct
9 Correct 2400 ms 209628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1905 ms 105984 KB Output is correct
3 Correct 2299 ms 209596 KB Output is correct
4 Correct 2333 ms 209632 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 205 ms 21156 KB Output is correct
7 Correct 207 ms 21280 KB Output is correct
8 Correct 205 ms 21172 KB Output is correct
9 Correct 203 ms 21152 KB Output is correct
10 Correct 197 ms 21160 KB Output is correct
11 Correct 205 ms 21144 KB Output is correct
12 Correct 211 ms 21148 KB Output is correct
13 Correct 209 ms 21144 KB Output is correct
14 Correct 215 ms 21148 KB Output is correct
15 Correct 214 ms 21256 KB Output is correct
16 Correct 227 ms 21260 KB Output is correct
17 Correct 209 ms 21260 KB Output is correct
18 Correct 2397 ms 209664 KB Output is correct
19 Correct 2416 ms 209748 KB Output is correct
20 Correct 2604 ms 209636 KB Output is correct
21 Correct 223 ms 21172 KB Output is correct
22 Correct 222 ms 21140 KB Output is correct
23 Correct 487 ms 26532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 219 ms 17520 KB Output is correct
3 Correct 219 ms 17580 KB Output is correct
4 Correct 2651 ms 178320 KB Output is correct
5 Correct 218 ms 21160 KB Output is correct
6 Correct 214 ms 21208 KB Output is correct
7 Correct 225 ms 21192 KB Output is correct
8 Correct 215 ms 21160 KB Output is correct
9 Correct 224 ms 21248 KB Output is correct
10 Correct 217 ms 21248 KB Output is correct
11 Correct 224 ms 21172 KB Output is correct
12 Correct 213 ms 21148 KB Output is correct
13 Correct 237 ms 21188 KB Output is correct
14 Correct 2742 ms 209676 KB Output is correct
15 Correct 254 ms 21152 KB Output is correct
16 Correct 2367 ms 209640 KB Output is correct
17 Correct 2280 ms 209680 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 19 ms 1996 KB Output is correct
3 Correct 20 ms 1968 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 18 ms 2000 KB Output is correct
17 Correct 186 ms 10924 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 224 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 496 KB Output is correct
28 Correct 975 ms 48824 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1905 ms 105984 KB Output is correct
31 Correct 2299 ms 209596 KB Output is correct
32 Correct 2333 ms 209632 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2301 ms 209652 KB Output is correct
35 Correct 1925 ms 143132 KB Output is correct
36 Correct 2359 ms 209652 KB Output is correct
37 Correct 2400 ms 209628 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 205 ms 21156 KB Output is correct
40 Correct 207 ms 21280 KB Output is correct
41 Correct 205 ms 21172 KB Output is correct
42 Correct 203 ms 21152 KB Output is correct
43 Correct 197 ms 21160 KB Output is correct
44 Correct 205 ms 21144 KB Output is correct
45 Correct 211 ms 21148 KB Output is correct
46 Correct 209 ms 21144 KB Output is correct
47 Correct 215 ms 21148 KB Output is correct
48 Correct 214 ms 21256 KB Output is correct
49 Correct 227 ms 21260 KB Output is correct
50 Correct 209 ms 21260 KB Output is correct
51 Correct 2397 ms 209664 KB Output is correct
52 Correct 2416 ms 209748 KB Output is correct
53 Correct 2604 ms 209636 KB Output is correct
54 Correct 223 ms 21172 KB Output is correct
55 Correct 222 ms 21140 KB Output is correct
56 Correct 487 ms 26532 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 219 ms 17520 KB Output is correct
59 Correct 219 ms 17580 KB Output is correct
60 Correct 2651 ms 178320 KB Output is correct
61 Correct 218 ms 21160 KB Output is correct
62 Correct 214 ms 21208 KB Output is correct
63 Correct 225 ms 21192 KB Output is correct
64 Correct 215 ms 21160 KB Output is correct
65 Correct 224 ms 21248 KB Output is correct
66 Correct 217 ms 21248 KB Output is correct
67 Correct 224 ms 21172 KB Output is correct
68 Correct 213 ms 21148 KB Output is correct
69 Correct 237 ms 21188 KB Output is correct
70 Correct 2742 ms 209676 KB Output is correct
71 Correct 254 ms 21152 KB Output is correct
72 Correct 2367 ms 209640 KB Output is correct
73 Correct 2280 ms 209680 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 304 KB Output is correct
76 Correct 1 ms 304 KB Output is correct
77 Correct 1 ms 300 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 19 ms 2384 KB Output is correct
80 Correct 2449 ms 209648 KB Output is correct
81 Correct 2517 ms 209692 KB Output is correct
82 Correct 2445 ms 209576 KB Output is correct
83 Correct 2449 ms 209644 KB Output is correct
84 Correct 2616 ms 209652 KB Output is correct
85 Correct 2530 ms 209604 KB Output is correct
86 Correct 436 ms 26460 KB Output is correct
87 Correct 1 ms 212 KB Output is correct