답안 #568690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568690 2022-05-26T05:20:35 Z joshjms 이상한 기계 (APIO19_strange_device) C++17
10 / 100
686 ms 50728 KB
#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;

    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) {ans += ls[i].fi - prv; prv = -1;}
    }

    cout << ans << "\n";

}

signed main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:62: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]
   62 |     for(int i = 0; i < ls.size(); i++) {
      |                    ~~^~~~~~~~~~~
strange_device.cpp:66:14: 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]
   66 |         if(i < ls.size() - 1 && ls[i].fi == ls[i + 1].fi) continue;
      |            ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1112 KB Output is correct
3 Correct 7 ms 1080 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 347 ms 48996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 528 ms 49008 KB Output is correct
3 Incorrect 520 ms 50268 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 528 ms 49008 KB Output is correct
3 Incorrect 520 ms 50268 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 528 ms 49008 KB Output is correct
3 Incorrect 520 ms 50268 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 66 ms 9736 KB Output is correct
3 Correct 84 ms 9792 KB Output is correct
4 Correct 686 ms 50508 KB Output is correct
5 Correct 63 ms 9800 KB Output is correct
6 Correct 60 ms 9792 KB Output is correct
7 Correct 56 ms 9744 KB Output is correct
8 Correct 58 ms 9800 KB Output is correct
9 Correct 71 ms 9796 KB Output is correct
10 Correct 77 ms 9764 KB Output is correct
11 Correct 58 ms 9832 KB Output is correct
12 Correct 51 ms 9840 KB Output is correct
13 Correct 61 ms 9748 KB Output is correct
14 Correct 654 ms 50728 KB Output is correct
15 Incorrect 59 ms 9924 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1112 KB Output is correct
3 Correct 7 ms 1080 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -