답안 #401380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
401380 2021-05-10T05:07:39 Z ZikXewen 이상한 기계 (APIO19_strange_device) C++17
35 / 100
526 ms 41444 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair<int64, int64> ii;
int N;
int64 A, B, per, ans;
vector<ii> ar;
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> N >> A >> B;
    if(A / __gcd(A, B + 1) >= LLONG_MAX / B) per = LLONG_MAX;
    per = A / __gcd(A, B + 1) * B;
    for(int64 i = 0, u, v; i < N; ++i){
        cin >> u >> v;
        if(v - u + 1 >= per) {cout << per; return 0;}
        u %= per, v %= per;
        if(u <= v) ar.emplace_back(u, v);
        else ar.emplace_back(u, per - 1), ar.emplace_back(0, v);
    }
    sort(ar.begin(), ar.end());
    for(int64 i = 0, l = 0, r = -1;; ++i){
        if(i == ar.size()) {ans += r - l + 1; break;}
        if(ar[i].first <= r) r = max(r, ar[i].second);
        else ans += r - l + 1, l = ar[i].first, r = ar[i].second;
    }
    cout << ans;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int64' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         if(i == ar.size()) {ans += r - l + 1; break;}
      |            ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 972 KB Output is correct
3 Correct 6 ms 996 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 996 KB Output is correct
17 Correct 50 ms 5620 KB Output is correct
18 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 342 ms 41444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 452 ms 32040 KB Output is correct
3 Correct 447 ms 32012 KB Output is correct
4 Correct 447 ms 32036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 452 ms 32040 KB Output is correct
3 Correct 447 ms 32012 KB Output is correct
4 Correct 447 ms 32036 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 446 ms 31988 KB Output is correct
7 Correct 452 ms 31968 KB Output is correct
8 Correct 447 ms 32132 KB Output is correct
9 Correct 481 ms 32036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 452 ms 32040 KB Output is correct
3 Correct 447 ms 32012 KB Output is correct
4 Correct 447 ms 32036 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 44 ms 5720 KB Output is correct
7 Correct 49 ms 5644 KB Output is correct
8 Correct 46 ms 5656 KB Output is correct
9 Correct 45 ms 5692 KB Output is correct
10 Correct 45 ms 5700 KB Output is correct
11 Correct 46 ms 5636 KB Output is correct
12 Correct 45 ms 5672 KB Output is correct
13 Correct 47 ms 5692 KB Output is correct
14 Correct 45 ms 5688 KB Output is correct
15 Correct 49 ms 5608 KB Output is correct
16 Correct 49 ms 5692 KB Output is correct
17 Correct 46 ms 5624 KB Output is correct
18 Correct 453 ms 31944 KB Output is correct
19 Correct 445 ms 31932 KB Output is correct
20 Correct 499 ms 31984 KB Output is correct
21 Correct 47 ms 5704 KB Output is correct
22 Correct 42 ms 5612 KB Output is correct
23 Correct 140 ms 18436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 48 ms 5652 KB Output is correct
3 Correct 49 ms 5652 KB Output is correct
4 Correct 526 ms 32032 KB Output is correct
5 Correct 49 ms 5692 KB Output is correct
6 Correct 47 ms 5724 KB Output is correct
7 Correct 48 ms 5716 KB Output is correct
8 Correct 48 ms 5692 KB Output is correct
9 Correct 48 ms 5692 KB Output is correct
10 Correct 48 ms 5656 KB Output is correct
11 Correct 48 ms 5748 KB Output is correct
12 Correct 45 ms 5684 KB Output is correct
13 Correct 49 ms 5692 KB Output is correct
14 Correct 490 ms 31940 KB Output is correct
15 Correct 50 ms 5692 KB Output is correct
16 Correct 453 ms 31984 KB Output is correct
17 Correct 451 ms 31956 KB Output is correct
18 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 972 KB Output is correct
3 Correct 6 ms 996 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 996 KB Output is correct
17 Correct 50 ms 5620 KB Output is correct
18 Incorrect 1 ms 204 KB Output isn't correct