# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
231112 | ChrisT | 이상한 기계 (APIO19_strange_device) | C++17 | 606 ms | 41368 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using pll = pair<ll,ll>;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define lc ind<<1
#define rc ind<<1|1
const int MN = 25e4+4, MOD = 1e9+7, BASE = 31;
int main () {
int n; ll a,b;
scanf ("%d %lld %lld",&n,&a,&b);
ll x = a/__gcd(a,b+1);
__int128 pp = (__int128)b*x;
ll p = (ll)min(pp,__int128(1e18+2));
vector<pll> segs;
while (n--) {
ll l,r;
scanf ("%lld %lld",&l,&r); if (r-l+1 >= p) return !printf ("%lld\n",p);
ll nxt = (l/p+1)*p;
if (nxt <= r) {
segs.emplace_back(l%p,(nxt-1)%p); segs.emplace_back(nxt%p,r%p);
} else segs.emplace_back(l%p,r%p);
}
sort(all(segs));
ll lr = -2; ll ret = 0;
for (auto &[l,r] : segs) {
if (r > lr) {
ret += r-max(lr+1,l)+1;
lr = r;
}
}
printf ("%lld\n",ret);
return 0;
}
/*
find period:
find first t>0 s/t t%b==0 && (t+t/b)%a==0
since b|t let t = xb for some minimal x
(xb+xb/b)%a == 0
(xb+x)%a==0
(x(b+1))%a==0
b+1 is constant, cancel out gcd(a,b+1)
x = a/gcd(a,b+1)
t = ba/gcd(a,b+1)
*/
컴파일 시 표준 에러 (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... |