# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1135961 | nathan4690 | 이상한 기계 (APIO19_strange_device) | C++20 | 457 ms | 33480 KiB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f1(i,n) for(int i=1;i<=n;i++)
#define __file_name ""
using namespace std;
const ll maxn = 1e6+5, inf=1e18;
ll n,a,b,v,ans;
vector<pair<ll,ll>> all;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if(fopen(__file_name ".inp", "r")){
freopen(__file_name ".inp","r",stdin);
freopen(__file_name ".out","w",stdout);
}
// code here
cin >> n >> a >> b;
v = a / __gcd(a, b + 1);
if(inf / b / v < 1) v = inf;
else v *= b;
f1(i,n){
ll l, r;
cin >> l >> r;
if(r - l + 1 >= v){
cout << v << '\n';
return 0;
}
if(l / v != r / v){
all.push_back({0, 1});
all.push_back({r % v + 1, -1});
all.push_back({l % v, 1});
all.push_back({v, -1});
}else{
all.push_back({l % v, 1});
all.push_back({r % v + 1, -1});
}
}
sort(all.begin(), all.end());
ll pre = inf, st = 0;
for(pair<ll,ll> item: all){
if(st == 0) pre = item.first;
// cout << item.first << ' ' << item.second << '\n';
st += item.second;
if(st == 0){
ans += max(0ll, item.first - pre);
pre = inf;
}
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (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... |