답안 #783645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
783645 2023-07-15T07:19:52 Z andecaandeci 이상한 기계 (APIO19_strange_device) C++17
5 / 100
418 ms 44420 KB
#include<bits/stdc++.h>
using namespace std;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
int n, a, b;
vector<pii> range;
bool comp(pii a, pii b) {
    return (a.fi < b.fi || (a.fi == b.fi && a.se < b.se));
}
signed main() {
    ioss;
    // cari cycle (bisa manual, baru cari pola)
    // --- a*b / fpb(a, b+1)
    // hitung segment aktif
    // line sweep
    cin >> n >> a >> b;
    __int128_t cycle = (__int128_t)a*b/(__gcd(a, (b+1)));
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int l, r; cin >> l >> r;
        if((r-l)+1 >= cycle) ans = cycle;

        l %= cycle, r %= cycle;
        if(l <= r) range.pb({l, r});
        else range.pb({l, cycle-1}), range.pb({0, r});
    }
    sort(range.begin(), range.end(), comp);
    
    if(ans == cycle) {
        cout << ans << endl;
        return 0;
    }

    auto [l, r] = range[0];
    ans = (r-l)+1;
    for(int i = 1; i < range.size(); i++) {
        auto [pl, pr] = range[i-1];
        auto [l, r] = range[i];
        if(pl <= l && pr >= r) continue;
        if(pl <= r && pr >= r) r = pl-1;
        if(pl <= l && pr >= l) l = pr+1;
        //cout << l << " " << r << endl;
        ans += (r-l)+1;
    }
    cout << ans << endl;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:40:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 1; i < range.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 4 ms 984 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 418 ms 44420 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 418 ms 44420 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 418 ms 44420 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 43 ms 5724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 4 ms 984 KB Output isn't correct
3 Halted 0 ms 0 KB -