| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 568716 | joshjms | 이상한 기계 (APIO19_strange_device) | C++17 | 657 ms | 50072 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << "\n";
const long long mod = 1e9 + 7;
const long long MAX = 1e18;
int n, a, b, L[1000005], R[1000005], s, m;
vector <pair<int,int>> ls;
int cnt, prv, ans;
void solve () {
cin >> n >> a >> b;
for(int i = 1; i <= n; i++) {
cin >> L[i] >> R[i];
s += R[i] - L[i] + 1;
}
if(MAX / a < b) {
cout << s << "\n";
return;
}
m = a * b / __gcd(a, b + 1);
for(int i = 1; i <= n; i++) {
if(R[i] - L[i] + 1 >= m) {
cout << m << "\n";
return;
}
}
for(int i = 1; i <= n; i++) {
L[i] %= m;
R[i] %= m;
if(R[i] < L[i]) {
ls.pb({L[i], 0});
ls.pb({m, 1});
ls.pb({0, 0});
ls.pb({R[i] + 1, 1});
}
else {
ls.pb({L[i], 0});
ls.pb({R[i] + 1, 1});
}
}
sort(ls.begin(), ls.end());
cnt = 0, prv = -1;
// for(auto i : ls) cout << i.fi << " ";
// cout << "\n";
for(int i = 0; i < ls.size(); i++) {
if(ls[i].se == 0) cnt++;
else cnt--;
if(i < ls.size() - 1 && ls[i].fi == ls[i + 1].fi) continue;
if(cnt > 0 && prv == -1) {prv = ls[i].fi;}
if(cnt == 0 && prv != -1) {ans += ls[i].fi - prv; prv = -1;}
}
if(prv != -1) ans += m - prv;
cout << ans << "\n";
}
signed main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}컴파일 시 표준 에러 (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... | ||||
