이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define N 20005
#define ff first
#define ss second
#define pb push_back
using namespace std;
ll gcd(ll a,ll b){
while(a!=0 && b!=0){
if(a>b){
a=a%b;
}
else b=b%a;
}
return max(a,b);
}
vector<pair<pair<ll,ll>,pair<ll,ll> > >v;
int main(){
ll n,a,b;
cin >> n >> a >> b;
ll k=gcd(a,(b+1));
k=a/k;
ll y=1e18;
for(int i=1;i<=n;i++){
ll l,r;
cin >> l >> r;
if(y/b>=k){
if(k*b<=(r-l+1)){
cout << k*b;
return 0;
}
}
ll x1=(l/b)%k;
ll y1=l%b;
ll x2=(r/b)%k;
ll y2=r%b;
// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << '\n';
if((x1==x2 && y2<y1) || x2<x1){
v.pb({{0,0},{x2,y2}});
v.pb({{x1,y1},{k-1,b-1}});
}
else v.pb({{x1,y1},{x2,y2}});
}
sort(v.begin(),v.end());
ll ans=0;
pair<ll,ll>e={-1,-1};
for(int i=0;i<v.size();i++){
ll x1=v[i].ff.ff;
ll y1=v[i].ff.ss;
ll x2=v[i].ss.ff;
ll y2=v[i].ss.ss;
if(e.ff>x2 || (e.ff==x2 && e.ss>=y2)){
continue;
}
if(x1>e.ff || (x1==e.ff && y1>e.ss)){
ans+=((x2-x1)*b+y2-y1+1);
e={x2,y2};
continue;
}
ans+=((x2-e.ff)*b+y2-e.ss);
e={x2,y2};
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'int main()':
strange_device.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# | 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... |