# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
272739 | kimbj0709 | Strange Device (APIO19_strange_device) | C++14 | 617 ms | 53440 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |