이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long llo;
#define ak first
#define bk second
#define endl "\n"
llo gcd(llo kk,llo ll){
if(ll==0){
return kk;
}
return gcd(ll,kk%ll);
}
const llo inf = (llo)1e18 + 3;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n,a,b;
cin>>n>>a>>b;
llo x;
vector<pair<llo,llo>> it;
x=b;
llo y=a/gcd(a,b+1);
/*if(y>1000000000000000000LL/b){
}*/
/* if((b+1)%a==0){
x=b;
}
else{
x=a*b;
}*/
llo aa,bb;
llo ss=0;
vector<pair<llo,llo>> ac;
for(llo i=0;i<n;i++){
cin>>aa>>bb;
ss+=bb-aa+1;
it.pb(mp(aa,bb));
}
if(x>(llo)2*(inf/b)){
cout<<ss<<endl;
return 0;
}
x*=(a/gcd(a,b+1));
for(llo i=0;i<n;i++){
aa=it[i].ak;
bb=it[i].bk;
if(bb-aa+1>=x){
cout<<x<<endl;
return 0;
}
/*if(bb-aa+1>=x){
ac.pb(mp(0,x-1));
}*/
aa%=x;
bb%=x;
if(bb<aa){
ac.pb(mp(aa,x-1));
ac.pb(mp(0,bb));
}
else{
ac.pb(mp(aa,bb));
}
}
/* if(s==1){
cout<<x<<endl;
}
else{*/
vector<pair<llo,llo>> prev;
sort(ac.begin(),ac.end());
for(auto cc:ac){
if(prev.size()==0){
prev.pb(cc);
}
else{
if(cc.ak>prev[prev.size()-1].bk){
prev.pb(cc);
}
else{
prev[prev.size()-1].bk=max(prev[prev.size()-1].bk,cc.bk);
}
}
}
llo tot=0;
for(llo i=0;i<prev.size();i++){
tot+=prev[i].bk-prev[i].ak+1;
}
/* if(s==1 and tot<x){
while(true){
int y=1;
}
}
*/
cout<<tot<<endl;
//}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'int main()':
strange_device.cpp:95:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(llo i=0;i<prev.size();i++){
~^~~~~~~~~~~~
strange_device.cpp:26:6: warning: unused variable 'y' [-Wunused-variable]
llo y=a/gcd(a,b+1);
^
# | 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... |