답안 #806646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
806646 2023-08-04T08:30:10 Z gg123_pe 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1323 ms 115864 KB
#include <bits/stdc++.h> 
using namespace std; 

typedef long long ll; 
#define f(i,a,b) for(int i = a; i < b; i++)
const int N = 1e6 + 5; 
const ll inf = 1e18 + 5; 

int n; 
ll l[N], r[N]; 
ll A, B, S; 

void subtask_1(){
    set <pair<ll,ll>> s;

    f(i,1,n+1){
        for(ll j = l[i]; j <= r[i]; j++){
            ll a, b; 
            a = (j + j/B) % A; 
            b = j % B; 
            s.insert({a, b}); 
        }
    }
    cout << s.size() << "\n"; 
}
void solve(){
    ll X = A / __gcd(A, B+1);  
    ll period = inf; 
    if(B <= inf/X) period = X * B;  

    set <pair<ll,ll>> s; 

    f(i,1,n+1){
        ll len = r[i] - l[i] + 1;  
        if(len >= period){
            cout << period << "\n"; 
            return; 
        }
        ll x = l[i] % period;
        if(len > period-x){
            s.insert({x, period-1}); 
            s.insert({0, r[i]%period}); 
        }   
        else{
            s.insert({x, r[i]%period}); 
        }
    }
    ll ans = 0, l, r;
    auto it = s.begin(); 
    l = it->first, r = it->second; 
    for(auto p: s){
        if(p == *it) continue; 
        ll x = p.first, y = p.second; 

        if(x <= r){
            r = max(r, y); 
        }
        else if(x == r+1){
            r = y; 
        }
        else{
            ans += r - l + 1; 
            l = x, r = y; 
        }
    }
    ans += r - l + 1; 
    cout << ans << "\n"; 
}
int main(){
    cin >> n >> A >> B; 

    f(i,1,n+1){
        cin >> l[i] >> r[i]; 
    }

    solve(); 

    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 11 ms 1092 KB Output is correct
3 Correct 11 ms 1092 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 11 ms 996 KB Output is correct
17 Correct 108 ms 8048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 264 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 702 ms 15884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1154 ms 78580 KB Output is correct
3 Correct 1128 ms 78564 KB Output is correct
4 Correct 1113 ms 78564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1154 ms 78580 KB Output is correct
3 Correct 1128 ms 78564 KB Output is correct
4 Correct 1113 ms 78564 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1160 ms 78660 KB Output is correct
7 Correct 1111 ms 78640 KB Output is correct
8 Correct 1129 ms 78532 KB Output is correct
9 Correct 1130 ms 78508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1154 ms 78580 KB Output is correct
3 Correct 1128 ms 78564 KB Output is correct
4 Correct 1113 ms 78564 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 121 ms 8264 KB Output is correct
7 Correct 119 ms 8132 KB Output is correct
8 Correct 108 ms 8108 KB Output is correct
9 Correct 107 ms 8036 KB Output is correct
10 Correct 104 ms 8012 KB Output is correct
11 Correct 111 ms 8200 KB Output is correct
12 Correct 106 ms 8072 KB Output is correct
13 Correct 109 ms 8108 KB Output is correct
14 Correct 107 ms 8092 KB Output is correct
15 Correct 123 ms 8064 KB Output is correct
16 Correct 109 ms 8072 KB Output is correct
17 Correct 108 ms 8108 KB Output is correct
18 Correct 1145 ms 78536 KB Output is correct
19 Correct 1121 ms 78556 KB Output is correct
20 Correct 1138 ms 78468 KB Output is correct
21 Correct 107 ms 8124 KB Output is correct
22 Correct 107 ms 8136 KB Output is correct
23 Correct 336 ms 5536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 108 ms 8236 KB Output is correct
3 Correct 108 ms 8000 KB Output is correct
4 Correct 1113 ms 78492 KB Output is correct
5 Correct 117 ms 8068 KB Output is correct
6 Correct 110 ms 8004 KB Output is correct
7 Correct 110 ms 8000 KB Output is correct
8 Correct 122 ms 8016 KB Output is correct
9 Correct 130 ms 8116 KB Output is correct
10 Correct 120 ms 8120 KB Output is correct
11 Correct 111 ms 8096 KB Output is correct
12 Correct 110 ms 8048 KB Output is correct
13 Correct 156 ms 8116 KB Output is correct
14 Correct 1163 ms 78692 KB Output is correct
15 Correct 112 ms 8036 KB Output is correct
16 Correct 1194 ms 78500 KB Output is correct
17 Correct 1110 ms 78648 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 11 ms 1092 KB Output is correct
3 Correct 11 ms 1092 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 11 ms 996 KB Output is correct
17 Correct 108 ms 8048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 264 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 702 ms 15884 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1154 ms 78580 KB Output is correct
31 Correct 1128 ms 78564 KB Output is correct
32 Correct 1113 ms 78564 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1160 ms 78660 KB Output is correct
35 Correct 1111 ms 78640 KB Output is correct
36 Correct 1129 ms 78532 KB Output is correct
37 Correct 1130 ms 78508 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 121 ms 8264 KB Output is correct
40 Correct 119 ms 8132 KB Output is correct
41 Correct 108 ms 8108 KB Output is correct
42 Correct 107 ms 8036 KB Output is correct
43 Correct 104 ms 8012 KB Output is correct
44 Correct 111 ms 8200 KB Output is correct
45 Correct 106 ms 8072 KB Output is correct
46 Correct 109 ms 8108 KB Output is correct
47 Correct 107 ms 8092 KB Output is correct
48 Correct 123 ms 8064 KB Output is correct
49 Correct 109 ms 8072 KB Output is correct
50 Correct 108 ms 8108 KB Output is correct
51 Correct 1145 ms 78536 KB Output is correct
52 Correct 1121 ms 78556 KB Output is correct
53 Correct 1138 ms 78468 KB Output is correct
54 Correct 107 ms 8124 KB Output is correct
55 Correct 107 ms 8136 KB Output is correct
56 Correct 336 ms 5536 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 108 ms 8236 KB Output is correct
59 Correct 108 ms 8000 KB Output is correct
60 Correct 1113 ms 78492 KB Output is correct
61 Correct 117 ms 8068 KB Output is correct
62 Correct 110 ms 8004 KB Output is correct
63 Correct 110 ms 8000 KB Output is correct
64 Correct 122 ms 8016 KB Output is correct
65 Correct 130 ms 8116 KB Output is correct
66 Correct 120 ms 8120 KB Output is correct
67 Correct 111 ms 8096 KB Output is correct
68 Correct 110 ms 8048 KB Output is correct
69 Correct 156 ms 8116 KB Output is correct
70 Correct 1163 ms 78692 KB Output is correct
71 Correct 112 ms 8036 KB Output is correct
72 Correct 1194 ms 78500 KB Output is correct
73 Correct 1110 ms 78648 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 304 KB Output is correct
78 Correct 1 ms 312 KB Output is correct
79 Correct 13 ms 1472 KB Output is correct
80 Correct 1146 ms 115708 KB Output is correct
81 Correct 1184 ms 115732 KB Output is correct
82 Correct 1234 ms 115864 KB Output is correct
83 Correct 1236 ms 115808 KB Output is correct
84 Correct 1323 ms 115764 KB Output is correct
85 Correct 1157 ms 115648 KB Output is correct
86 Correct 323 ms 18140 KB Output is correct
87 Correct 1 ms 212 KB Output is correct