답안 #382903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382903 2021-03-28T11:47:01 Z danielcm585 이상한 기계 (APIO19_strange_device) C++14
35 / 100
776 ms 61528 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<ll,ll> ii;

const int N = 1e6;
ll n, a, b;
ll l[N+2], r[N+2];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) {
        cin >> l[i] >> r[i];
    }
    ll cyc = a/__gcd(a,b+1)*b;
    for (int i = 1; i <= n; i++) {
        if (r[i]-l[i]+1 >= cyc) {
            cout << cyc << '\n';
            return 0;
        }
    }
    // cout << ">> " << cyc << '\n';
    vector<ii> v;
    for (int i = 1; i <= n; i++) {
        l[i] %= cyc, r[i] %= cyc;
        // cout << l[i] << ' ' << r[i] << '\n';
        v.push_back(ii(l[i],1));
        v.push_back(ii(r[i]+1,-1));
        if (l[i] > r[i]) {
            v.push_back({0,1});
        }
    }
    v.push_back({cyc,-1});
    assert(v.size() <= 4*n);
    sort(v.begin(),v.end());
    ll ans = 0, cur = 0, ls = -1;
    for (int i = 0; i < v.size(); ) {
        ll pos = v[i].fi;
        if (cur > 0) ans += pos-ls;
        // cout << ls+1 << ' ' << pos << " -> " << cur << '\n';
        while (i < v.size() && v[i].fi == pos) {
            cur += v[i].se, i++;
        }
        ls = pos;
    }
    cout << ans << '\n';
    return 0;
}

/*
0,0 -> 1,1 -> ... -> 0,0

t%a==0
t%(b+1)==0
a*(b+1)/f(a,b+1)-k/(b+1)
= a*(b+1)/f(a,b+1)-a*(b+1)/f/(b+1)
= a*(b+1)/f(a,b+1)-a/f
= a*b/f
L R

---------
 ----------------
                     -----------------
                            ----------
-------
*/

Compilation message

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from strange_device.cpp:1:
strange_device.cpp: In function 'int main()':
strange_device.cpp:39:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   39 |     assert(v.size() <= 4*n);
      |            ~~~~~~~~~^~~~~~
strange_device.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int i = 0; i < v.size(); ) {
      |                     ~~^~~~~~~~~~
strange_device.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         while (i < v.size() && v[i].fi == pos) {
      |                ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 7 ms 1520 KB Output is correct
3 Correct 7 ms 1520 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 8 ms 1520 KB Output is correct
17 Correct 69 ms 8420 KB Output is correct
18 Incorrect 2 ms 364 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 402 ms 51020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 594 ms 61528 KB Output is correct
3 Correct 623 ms 49356 KB Output is correct
4 Correct 566 ms 49692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 594 ms 61528 KB Output is correct
3 Correct 623 ms 49356 KB Output is correct
4 Correct 566 ms 49692 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 561 ms 49464 KB Output is correct
7 Correct 549 ms 49356 KB Output is correct
8 Correct 572 ms 52556 KB Output is correct
9 Correct 689 ms 53488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 594 ms 61528 KB Output is correct
3 Correct 623 ms 49356 KB Output is correct
4 Correct 566 ms 49692 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 55 ms 8420 KB Output is correct
7 Correct 61 ms 8420 KB Output is correct
8 Correct 54 ms 9316 KB Output is correct
9 Correct 61 ms 9316 KB Output is correct
10 Correct 56 ms 8420 KB Output is correct
11 Correct 61 ms 9316 KB Output is correct
12 Correct 69 ms 8932 KB Output is correct
13 Correct 62 ms 9316 KB Output is correct
14 Correct 57 ms 8036 KB Output is correct
15 Correct 65 ms 7780 KB Output is correct
16 Correct 64 ms 9444 KB Output is correct
17 Correct 54 ms 7780 KB Output is correct
18 Correct 569 ms 56872 KB Output is correct
19 Correct 617 ms 57300 KB Output is correct
20 Correct 697 ms 57304 KB Output is correct
21 Correct 71 ms 7780 KB Output is correct
22 Correct 55 ms 7780 KB Output is correct
23 Correct 176 ms 31068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 66 ms 9956 KB Output is correct
3 Correct 64 ms 8420 KB Output is correct
4 Correct 776 ms 57164 KB Output is correct
5 Correct 63 ms 9188 KB Output is correct
6 Correct 63 ms 9188 KB Output is correct
7 Correct 63 ms 8676 KB Output is correct
8 Correct 66 ms 9188 KB Output is correct
9 Correct 64 ms 9060 KB Output is correct
10 Correct 66 ms 8292 KB Output is correct
11 Correct 64 ms 8676 KB Output is correct
12 Correct 57 ms 9188 KB Output is correct
13 Correct 67 ms 9188 KB Output is correct
14 Correct 709 ms 56908 KB Output is correct
15 Correct 69 ms 9188 KB Output is correct
16 Correct 573 ms 55384 KB Output is correct
17 Correct 559 ms 53580 KB Output is correct
18 Incorrect 2 ms 364 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 7 ms 1520 KB Output is correct
3 Correct 7 ms 1520 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 8 ms 1520 KB Output is correct
17 Correct 69 ms 8420 KB Output is correct
18 Incorrect 2 ms 364 KB Output isn't correct