Submission #782442

# Submission time Handle Problem Language Result Execution time Memory
782442 2023-07-14T01:44:26 Z christinelynn Strange Device (APIO19_strange_device) C++17
100 / 100
384 ms 32572 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long


signed main() {
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int n, a, b, c;
  cin >> n >> a >> b;
  vector<pair<int, int>> v;
  int arr[n], ARR[n];
  for(int i = 0; i < n; i++) {
    cin >> arr[i] >> ARR[i];
  }
  
  c = b + 1;
  int d = __gcd(c, a);
  int e;
  string s = to_string(a);
  string t = to_string(b);
  string q = to_string(d);
  if(s.length() + t.length() - q.length() > 18) {
    e = 1000000000000000000;
  } else {
    e = a / d;
    e *= b;
  }
  
  for(int i = 0; i < n; i++) {
    if(ARR[i] - arr[i] + 1 >= e) {
      cout << e << "\n";
      return 0;
    }
    if((ARR[i] % e) <= (arr[i] % e) && arr[i] < ARR[i]) {
      v.push_back({0, ARR[i] % e});
      v.push_back({arr[i] % e, e - 1});
    } else {
      v.push_back({arr[i] % e, ARR[i] % e});
    }
  }
  sort(v.begin(), v.end());
  int jum = 0, ka = -1;
  for(int i = 0; i < v.size(); i++) {
    if(v[i].first <= ka) {
      if(v[i].second <= ka) {
        
      } else {
        jum += v[i].second - ka;
        ka = v[i].second;
      }
    } else {
      jum += v[i].second - v[i].first + 1;
      ka = v[i].second;
    }
  }
  cout << jum << "\n";
  
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:43:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 1 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 4 ms 852 KB Output is correct
17 Correct 34 ms 4056 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 218 ms 32468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 321 ms 32440 KB Output is correct
3 Correct 335 ms 32448 KB Output is correct
4 Correct 319 ms 32456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 321 ms 32440 KB Output is correct
3 Correct 335 ms 32448 KB Output is correct
4 Correct 319 ms 32456 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 319 ms 32448 KB Output is correct
7 Correct 324 ms 32448 KB Output is correct
8 Correct 327 ms 32440 KB Output is correct
9 Correct 334 ms 32444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 321 ms 32440 KB Output is correct
3 Correct 335 ms 32448 KB Output is correct
4 Correct 319 ms 32456 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 30 ms 4048 KB Output is correct
7 Correct 32 ms 4048 KB Output is correct
8 Correct 29 ms 4052 KB Output is correct
9 Correct 30 ms 4048 KB Output is correct
10 Correct 30 ms 4056 KB Output is correct
11 Correct 31 ms 4056 KB Output is correct
12 Correct 29 ms 4044 KB Output is correct
13 Correct 31 ms 4056 KB Output is correct
14 Correct 29 ms 4044 KB Output is correct
15 Correct 33 ms 4044 KB Output is correct
16 Correct 32 ms 4048 KB Output is correct
17 Correct 30 ms 4044 KB Output is correct
18 Correct 314 ms 32444 KB Output is correct
19 Correct 313 ms 32452 KB Output is correct
20 Correct 328 ms 32444 KB Output is correct
21 Correct 32 ms 4048 KB Output is correct
22 Correct 29 ms 4048 KB Output is correct
23 Correct 93 ms 13940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 32 ms 3948 KB Output is correct
3 Correct 32 ms 4044 KB Output is correct
4 Correct 355 ms 32440 KB Output is correct
5 Correct 31 ms 4048 KB Output is correct
6 Correct 32 ms 4048 KB Output is correct
7 Correct 32 ms 4044 KB Output is correct
8 Correct 33 ms 4040 KB Output is correct
9 Correct 31 ms 4052 KB Output is correct
10 Correct 32 ms 4056 KB Output is correct
11 Correct 32 ms 4068 KB Output is correct
12 Correct 28 ms 4044 KB Output is correct
13 Correct 32 ms 4048 KB Output is correct
14 Correct 329 ms 32464 KB Output is correct
15 Correct 32 ms 4048 KB Output is correct
16 Correct 309 ms 32448 KB Output is correct
17 Correct 321 ms 32448 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 1 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 4 ms 852 KB Output is correct
17 Correct 34 ms 4056 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 218 ms 32468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 321 ms 32440 KB Output is correct
31 Correct 335 ms 32448 KB Output is correct
32 Correct 319 ms 32456 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 319 ms 32448 KB Output is correct
35 Correct 324 ms 32448 KB Output is correct
36 Correct 327 ms 32440 KB Output is correct
37 Correct 334 ms 32444 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 30 ms 4048 KB Output is correct
40 Correct 32 ms 4048 KB Output is correct
41 Correct 29 ms 4052 KB Output is correct
42 Correct 30 ms 4048 KB Output is correct
43 Correct 30 ms 4056 KB Output is correct
44 Correct 31 ms 4056 KB Output is correct
45 Correct 29 ms 4044 KB Output is correct
46 Correct 31 ms 4056 KB Output is correct
47 Correct 29 ms 4044 KB Output is correct
48 Correct 33 ms 4044 KB Output is correct
49 Correct 32 ms 4048 KB Output is correct
50 Correct 30 ms 4044 KB Output is correct
51 Correct 314 ms 32444 KB Output is correct
52 Correct 313 ms 32452 KB Output is correct
53 Correct 328 ms 32444 KB Output is correct
54 Correct 32 ms 4048 KB Output is correct
55 Correct 29 ms 4048 KB Output is correct
56 Correct 93 ms 13940 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 32 ms 3948 KB Output is correct
59 Correct 32 ms 4044 KB Output is correct
60 Correct 355 ms 32440 KB Output is correct
61 Correct 31 ms 4048 KB Output is correct
62 Correct 32 ms 4048 KB Output is correct
63 Correct 32 ms 4044 KB Output is correct
64 Correct 33 ms 4040 KB Output is correct
65 Correct 31 ms 4052 KB Output is correct
66 Correct 32 ms 4056 KB Output is correct
67 Correct 32 ms 4068 KB Output is correct
68 Correct 28 ms 4044 KB Output is correct
69 Correct 32 ms 4048 KB Output is correct
70 Correct 329 ms 32464 KB Output is correct
71 Correct 32 ms 4048 KB Output is correct
72 Correct 309 ms 32448 KB Output is correct
73 Correct 321 ms 32448 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 1 ms 232 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 3 ms 852 KB Output is correct
80 Correct 362 ms 32448 KB Output is correct
81 Correct 369 ms 32444 KB Output is correct
82 Correct 384 ms 32448 KB Output is correct
83 Correct 338 ms 32448 KB Output is correct
84 Correct 339 ms 32448 KB Output is correct
85 Correct 351 ms 32572 KB Output is correct
86 Correct 90 ms 13916 KB Output is correct
87 Correct 0 ms 212 KB Output is correct