Submission #272739

# Submission time Handle Problem Language Result Execution time Memory
272739 2020-08-18T14:56:53 Z kimbj0709 Strange Device (APIO19_strange_device) C++14
100 / 100
617 ms 53440 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mx = 1000000000000000000;
#define f first
#define s second
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int n,a,b;
  int input1,input2;
  cin >> n >> a >> b;
  int c = a/(__gcd(a,b+1));
  if(c>(mx+b-1)/b){
    mx = mx+1;
  }
  else{
    mx = c*b;
  }
  vector<pair<int,int> > vect1;
  for(int i=0;i<n;i++){
    cin >> input1 >> input2;
    if(input2-input1+1>=mx){
      cout << mx;
      return 0;
    }
    input1 %= mx;
    input2 %= mx;
    if(input1>input2){
      vect1.push_back({0,input2});
      vect1.push_back({input1,mx-1});
    }
    else{
      vect1.push_back({input1,input2});
    }
  }
  sort(vect1.begin(),vect1.end());
  int ans = 0;
  int currpos = -1;
  for(int i=0;i<vect1.size();i++){
    if(vect1[i].f>currpos){
      ans += vect1[i].s-vect1[i].f+1;
      currpos = vect1[i].s;
    }
    else if(vect1[i].s>currpos){
      ans += vect1[i].s-currpos;
      currpos = vect1[i].s;
    }
  }
  cout << ans;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:40:16: 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]
   40 |   for(int i=0;i<vect1.size();i++){
      |               ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 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 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 50 ms 5740 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 375 ms 41284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 483 ms 35208 KB Output is correct
3 Correct 470 ms 34740 KB Output is correct
4 Correct 451 ms 29888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 483 ms 35208 KB Output is correct
3 Correct 470 ms 34740 KB Output is correct
4 Correct 451 ms 29888 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 455 ms 30016 KB Output is correct
7 Correct 468 ms 30016 KB Output is correct
8 Correct 473 ms 30168 KB Output is correct
9 Correct 513 ms 29892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 483 ms 35208 KB Output is correct
3 Correct 470 ms 34740 KB Output is correct
4 Correct 451 ms 29888 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 47 ms 5680 KB Output is correct
7 Correct 48 ms 5740 KB Output is correct
8 Correct 48 ms 5740 KB Output is correct
9 Correct 47 ms 5740 KB Output is correct
10 Correct 50 ms 5740 KB Output is correct
11 Correct 61 ms 5736 KB Output is correct
12 Correct 70 ms 5736 KB Output is correct
13 Correct 48 ms 5740 KB Output is correct
14 Correct 53 ms 5740 KB Output is correct
15 Correct 51 ms 5736 KB Output is correct
16 Correct 50 ms 5740 KB Output is correct
17 Correct 60 ms 5740 KB Output is correct
18 Correct 463 ms 33384 KB Output is correct
19 Correct 466 ms 31956 KB Output is correct
20 Correct 519 ms 32580 KB Output is correct
21 Correct 52 ms 5740 KB Output is correct
22 Correct 43 ms 5740 KB Output is correct
23 Correct 170 ms 18528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 49 ms 5736 KB Output is correct
3 Correct 49 ms 5740 KB Output is correct
4 Correct 617 ms 33380 KB Output is correct
5 Correct 50 ms 5736 KB Output is correct
6 Correct 48 ms 5736 KB Output is correct
7 Correct 51 ms 5732 KB Output is correct
8 Correct 51 ms 5740 KB Output is correct
9 Correct 49 ms 5868 KB Output is correct
10 Correct 51 ms 5740 KB Output is correct
11 Correct 49 ms 5772 KB Output is correct
12 Correct 46 ms 5736 KB Output is correct
13 Correct 48 ms 5740 KB Output is correct
14 Correct 507 ms 34680 KB Output is correct
15 Correct 48 ms 5740 KB Output is correct
16 Correct 456 ms 27484 KB Output is correct
17 Correct 448 ms 33984 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 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 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 50 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 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 375 ms 41284 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 483 ms 35208 KB Output is correct
31 Correct 470 ms 34740 KB Output is correct
32 Correct 451 ms 29888 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 455 ms 30016 KB Output is correct
35 Correct 468 ms 30016 KB Output is correct
36 Correct 473 ms 30168 KB Output is correct
37 Correct 513 ms 29892 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 47 ms 5680 KB Output is correct
40 Correct 48 ms 5740 KB Output is correct
41 Correct 48 ms 5740 KB Output is correct
42 Correct 47 ms 5740 KB Output is correct
43 Correct 50 ms 5740 KB Output is correct
44 Correct 61 ms 5736 KB Output is correct
45 Correct 70 ms 5736 KB Output is correct
46 Correct 48 ms 5740 KB Output is correct
47 Correct 53 ms 5740 KB Output is correct
48 Correct 51 ms 5736 KB Output is correct
49 Correct 50 ms 5740 KB Output is correct
50 Correct 60 ms 5740 KB Output is correct
51 Correct 463 ms 33384 KB Output is correct
52 Correct 466 ms 31956 KB Output is correct
53 Correct 519 ms 32580 KB Output is correct
54 Correct 52 ms 5740 KB Output is correct
55 Correct 43 ms 5740 KB Output is correct
56 Correct 170 ms 18528 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 49 ms 5736 KB Output is correct
59 Correct 49 ms 5740 KB Output is correct
60 Correct 617 ms 33380 KB Output is correct
61 Correct 50 ms 5736 KB Output is correct
62 Correct 48 ms 5736 KB Output is correct
63 Correct 51 ms 5732 KB Output is correct
64 Correct 51 ms 5740 KB Output is correct
65 Correct 49 ms 5868 KB Output is correct
66 Correct 51 ms 5740 KB Output is correct
67 Correct 49 ms 5772 KB Output is correct
68 Correct 46 ms 5736 KB Output is correct
69 Correct 48 ms 5740 KB Output is correct
70 Correct 507 ms 34680 KB Output is correct
71 Correct 48 ms 5740 KB Output is correct
72 Correct 456 ms 27484 KB Output is correct
73 Correct 448 ms 33984 KB Output is correct
74 Correct 0 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 0 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 5 ms 1152 KB Output is correct
80 Correct 542 ms 53440 KB Output is correct
81 Correct 533 ms 53312 KB Output is correct
82 Correct 516 ms 53392 KB Output is correct
83 Correct 519 ms 53312 KB Output is correct
84 Correct 502 ms 53328 KB Output is correct
85 Correct 517 ms 42928 KB Output is correct
86 Correct 143 ms 18528 KB Output is correct
87 Correct 1 ms 384 KB Output is correct