Submission #781633

# Submission time Handle Problem Language Result Execution time Memory
781633 2023-07-13T08:58:04 Z makanhulia Strange Device (APIO19_strange_device) C++17
100 / 100
362 ms 33980 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 4 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 288 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 1224 KB Output is correct
17 Correct 36 ms 5176 KB Output is correct
18 Correct 0 ms 320 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 214 ms 32444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 302 ms 32448 KB Output is correct
3 Correct 304 ms 32448 KB Output is correct
4 Correct 310 ms 32736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 302 ms 32448 KB Output is correct
3 Correct 304 ms 32448 KB Output is correct
4 Correct 310 ms 32736 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 312 ms 32708 KB Output is correct
7 Correct 318 ms 32788 KB Output is correct
8 Correct 300 ms 32768 KB Output is correct
9 Correct 330 ms 32752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 302 ms 32448 KB Output is correct
3 Correct 304 ms 32448 KB Output is correct
4 Correct 310 ms 32736 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 32 ms 6984 KB Output is correct
7 Correct 34 ms 6972 KB Output is correct
8 Correct 32 ms 6976 KB Output is correct
9 Correct 32 ms 6916 KB Output is correct
10 Correct 32 ms 7000 KB Output is correct
11 Correct 33 ms 6976 KB Output is correct
12 Correct 31 ms 6956 KB Output is correct
13 Correct 35 ms 6976 KB Output is correct
14 Correct 31 ms 6972 KB Output is correct
15 Correct 35 ms 6972 KB Output is correct
16 Correct 34 ms 6928 KB Output is correct
17 Correct 32 ms 6972 KB Output is correct
18 Correct 309 ms 32768 KB Output is correct
19 Correct 296 ms 32764 KB Output is correct
20 Correct 321 ms 32792 KB Output is correct
21 Correct 37 ms 6936 KB Output is correct
22 Correct 30 ms 6956 KB Output is correct
23 Correct 92 ms 16740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 36 ms 4044 KB Output is correct
3 Correct 32 ms 4052 KB Output is correct
4 Correct 342 ms 32448 KB Output is correct
5 Correct 31 ms 4040 KB Output is correct
6 Correct 31 ms 4040 KB Output is correct
7 Correct 31 ms 4052 KB Output is correct
8 Correct 36 ms 4052 KB Output is correct
9 Correct 31 ms 4052 KB Output is correct
10 Correct 32 ms 4052 KB Output is correct
11 Correct 32 ms 4004 KB Output is correct
12 Correct 27 ms 4048 KB Output is correct
13 Correct 32 ms 4048 KB Output is correct
14 Correct 319 ms 32428 KB Output is correct
15 Correct 31 ms 4048 KB Output is correct
16 Correct 307 ms 32760 KB Output is correct
17 Correct 304 ms 32748 KB Output is correct
18 Correct 1 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 4 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 288 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 1224 KB Output is correct
17 Correct 36 ms 5176 KB Output is correct
18 Correct 0 ms 320 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 214 ms 32444 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 302 ms 32448 KB Output is correct
31 Correct 304 ms 32448 KB Output is correct
32 Correct 310 ms 32736 KB Output is correct
33 Correct 1 ms 316 KB Output is correct
34 Correct 312 ms 32708 KB Output is correct
35 Correct 318 ms 32788 KB Output is correct
36 Correct 300 ms 32768 KB Output is correct
37 Correct 330 ms 32752 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 32 ms 6984 KB Output is correct
40 Correct 34 ms 6972 KB Output is correct
41 Correct 32 ms 6976 KB Output is correct
42 Correct 32 ms 6916 KB Output is correct
43 Correct 32 ms 7000 KB Output is correct
44 Correct 33 ms 6976 KB Output is correct
45 Correct 31 ms 6956 KB Output is correct
46 Correct 35 ms 6976 KB Output is correct
47 Correct 31 ms 6972 KB Output is correct
48 Correct 35 ms 6972 KB Output is correct
49 Correct 34 ms 6928 KB Output is correct
50 Correct 32 ms 6972 KB Output is correct
51 Correct 309 ms 32768 KB Output is correct
52 Correct 296 ms 32764 KB Output is correct
53 Correct 321 ms 32792 KB Output is correct
54 Correct 37 ms 6936 KB Output is correct
55 Correct 30 ms 6956 KB Output is correct
56 Correct 92 ms 16740 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 36 ms 4044 KB Output is correct
59 Correct 32 ms 4052 KB Output is correct
60 Correct 342 ms 32448 KB Output is correct
61 Correct 31 ms 4040 KB Output is correct
62 Correct 31 ms 4040 KB Output is correct
63 Correct 31 ms 4052 KB Output is correct
64 Correct 36 ms 4052 KB Output is correct
65 Correct 31 ms 4052 KB Output is correct
66 Correct 32 ms 4052 KB Output is correct
67 Correct 32 ms 4004 KB Output is correct
68 Correct 27 ms 4048 KB Output is correct
69 Correct 32 ms 4048 KB Output is correct
70 Correct 319 ms 32428 KB Output is correct
71 Correct 31 ms 4048 KB Output is correct
72 Correct 307 ms 32760 KB Output is correct
73 Correct 304 ms 32748 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 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 4 ms 1236 KB Output is correct
80 Correct 354 ms 33848 KB Output is correct
81 Correct 362 ms 33980 KB Output is correct
82 Correct 327 ms 33848 KB Output is correct
83 Correct 330 ms 33784 KB Output is correct
84 Correct 327 ms 33844 KB Output is correct
85 Correct 333 ms 33752 KB Output is correct
86 Correct 93 ms 26432 KB Output is correct
87 Correct 0 ms 212 KB Output is correct