답안 #800968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800968 2023-08-02T03:07:57 Z abczz 이상한 기계 (APIO19_strange_device) C++17
100 / 100
1194 ms 69040 KB
#include <iostream>
#include <numeric>
#include <array>
#include <algorithm>
#include <vector>
#define ll long long

using namespace std;

ll n, a, b, l, r, x, y, z;
string S;
vector <array<__int128, 2>> V;
__int128 cl, cr, k, p, f;

void print(__int128 v) {
  S.clear();
  while (v) {
    S.push_back(char('0'+v%10));
    v /= 10;
  }
  if (S.empty()) S.push_back('0');
  reverse(S.begin(), S.end());
  cout << S << '\n';
}
int main() {
  cin >> n >> a >> b;
  x = (b+1)%a, y = a;
  z = gcd(x, y);
  k = y/z;
  k *= b;
  for (int i=0; i<n; ++i) {
    cin >> l >> r;
    cl = l, cr = r;
    cr = min(cl+k-1, cr);
    cl %= k;
    cr %= k;
    if (cl > cr) {
      V.push_back({cl, k-1});
      V.push_back({0, cr});
    }
    else V.push_back({cl, cr});
  }
  sort(V.begin(), V.end());
  p = -1;
  for (auto [l, r] : V) {
    if (l <= p && p <= r) {
      f += r-p;
    }
    else if (p < l) {
      f += r-l+1;
    }
    p = max(p, r);
  }
  print(f);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 14 ms 1332 KB Output is correct
3 Correct 11 ms 1276 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 11 ms 1232 KB Output is correct
17 Correct 114 ms 7280 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 771 ms 56924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1113 ms 68952 KB Output is correct
3 Correct 1056 ms 68852 KB Output is correct
4 Correct 1083 ms 69000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1113 ms 68952 KB Output is correct
3 Correct 1056 ms 68852 KB Output is correct
4 Correct 1083 ms 69000 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1100 ms 69028 KB Output is correct
7 Correct 1117 ms 68864 KB Output is correct
8 Correct 1044 ms 68928 KB Output is correct
9 Correct 1175 ms 68852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1113 ms 68952 KB Output is correct
3 Correct 1056 ms 68852 KB Output is correct
4 Correct 1083 ms 69000 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 102 ms 7220 KB Output is correct
7 Correct 107 ms 7228 KB Output is correct
8 Correct 103 ms 7192 KB Output is correct
9 Correct 111 ms 7356 KB Output is correct
10 Correct 101 ms 7180 KB Output is correct
11 Correct 105 ms 7220 KB Output is correct
12 Correct 103 ms 7172 KB Output is correct
13 Correct 108 ms 7196 KB Output is correct
14 Correct 101 ms 7228 KB Output is correct
15 Correct 109 ms 7256 KB Output is correct
16 Correct 107 ms 7160 KB Output is correct
17 Correct 106 ms 7268 KB Output is correct
18 Correct 1073 ms 68824 KB Output is correct
19 Correct 1051 ms 68880 KB Output is correct
20 Correct 1184 ms 68928 KB Output is correct
21 Correct 108 ms 7152 KB Output is correct
22 Correct 103 ms 7152 KB Output is correct
23 Correct 353 ms 26768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 106 ms 7200 KB Output is correct
3 Correct 112 ms 7216 KB Output is correct
4 Correct 1194 ms 68904 KB Output is correct
5 Correct 108 ms 7264 KB Output is correct
6 Correct 106 ms 7256 KB Output is correct
7 Correct 107 ms 7252 KB Output is correct
8 Correct 109 ms 7188 KB Output is correct
9 Correct 115 ms 7264 KB Output is correct
10 Correct 154 ms 7216 KB Output is correct
11 Correct 106 ms 7216 KB Output is correct
12 Correct 105 ms 7212 KB Output is correct
13 Correct 107 ms 7196 KB Output is correct
14 Correct 1118 ms 68856 KB Output is correct
15 Correct 106 ms 7184 KB Output is correct
16 Correct 1045 ms 68836 KB Output is correct
17 Correct 1058 ms 68980 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 14 ms 1332 KB Output is correct
3 Correct 11 ms 1276 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 11 ms 1232 KB Output is correct
17 Correct 114 ms 7280 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 771 ms 56924 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1113 ms 68952 KB Output is correct
31 Correct 1056 ms 68852 KB Output is correct
32 Correct 1083 ms 69000 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1100 ms 69028 KB Output is correct
35 Correct 1117 ms 68864 KB Output is correct
36 Correct 1044 ms 68928 KB Output is correct
37 Correct 1175 ms 68852 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 102 ms 7220 KB Output is correct
40 Correct 107 ms 7228 KB Output is correct
41 Correct 103 ms 7192 KB Output is correct
42 Correct 111 ms 7356 KB Output is correct
43 Correct 101 ms 7180 KB Output is correct
44 Correct 105 ms 7220 KB Output is correct
45 Correct 103 ms 7172 KB Output is correct
46 Correct 108 ms 7196 KB Output is correct
47 Correct 101 ms 7228 KB Output is correct
48 Correct 109 ms 7256 KB Output is correct
49 Correct 107 ms 7160 KB Output is correct
50 Correct 106 ms 7268 KB Output is correct
51 Correct 1073 ms 68824 KB Output is correct
52 Correct 1051 ms 68880 KB Output is correct
53 Correct 1184 ms 68928 KB Output is correct
54 Correct 108 ms 7152 KB Output is correct
55 Correct 103 ms 7152 KB Output is correct
56 Correct 353 ms 26768 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 106 ms 7200 KB Output is correct
59 Correct 112 ms 7216 KB Output is correct
60 Correct 1194 ms 68904 KB Output is correct
61 Correct 108 ms 7264 KB Output is correct
62 Correct 106 ms 7256 KB Output is correct
63 Correct 107 ms 7252 KB Output is correct
64 Correct 109 ms 7188 KB Output is correct
65 Correct 115 ms 7264 KB Output is correct
66 Correct 154 ms 7216 KB Output is correct
67 Correct 106 ms 7216 KB Output is correct
68 Correct 105 ms 7212 KB Output is correct
69 Correct 107 ms 7196 KB Output is correct
70 Correct 1118 ms 68856 KB Output is correct
71 Correct 106 ms 7184 KB Output is correct
72 Correct 1045 ms 68836 KB Output is correct
73 Correct 1058 ms 68980 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 10 ms 1200 KB Output is correct
80 Correct 1155 ms 68976 KB Output is correct
81 Correct 1167 ms 69040 KB Output is correct
82 Correct 1101 ms 68808 KB Output is correct
83 Correct 1124 ms 68932 KB Output is correct
84 Correct 1108 ms 68912 KB Output is correct
85 Correct 1110 ms 68912 KB Output is correct
86 Correct 341 ms 26796 KB Output is correct
87 Correct 1 ms 212 KB Output is correct