답안 #798651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798651 2023-07-30T22:27:16 Z gg123_pe 이상한 기계 (APIO19_strange_device) C++14
20 / 100
1218 ms 115744 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 subtask_2(){
    ll X = A / __gcd(A, B+1);  
    ll period = X * B;  
    cout << min(r[1] - l[1] + 1, period) << "\n"; 
}
void subtask_4(){
    if(A%2 == 0) A /= 2; 

    set <pair<ll,ll>> s; 

    f(i,1,n+1){
        ll len = r[i] - l[i] + 1;  
        if(len >= A){
            cout << A << "\n"; 
            return; 
        }
        ll x = l[i] % A;
        if(len > A-x){
            s.insert({x, A-1}); 
            s.insert({0, r[i]%A}); 
        }   
        else{
            s.insert({x, r[i]%A}); 
        }
    }
    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]; 
        S += r[i] - l[i] + 1; 
    }

    if(S <= N){
        subtask_1(); 
        return 0; 
    }
    if(n == 1){
        subtask_2(); 
        return 0; 
    }
    if(B == 1){
        subtask_4(); 
        return 0; 
    }
    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 43 ms 12704 KB Output is correct
3 Correct 59 ms 18308 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 7 ms 1108 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 33 ms 6964 KB Output is correct
16 Correct 30 ms 7124 KB Output is correct
17 Correct 137 ms 8432 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 123 ms 32216 KB Output is correct
3 Correct 165 ms 32040 KB Output is correct
4 Correct 101 ms 30540 KB Output is correct
5 Incorrect 754 ms 15936 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1177 ms 78520 KB Output is correct
3 Correct 1218 ms 115628 KB Output is correct
4 Correct 1163 ms 115744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1177 ms 78520 KB Output is correct
3 Correct 1218 ms 115628 KB Output is correct
4 Correct 1163 ms 115744 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 1012 ms 53020 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1177 ms 78520 KB Output is correct
3 Correct 1218 ms 115628 KB Output is correct
4 Correct 1163 ms 115744 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 97 ms 5548 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 92 ms 2104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 43 ms 12704 KB Output is correct
3 Correct 59 ms 18308 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 7 ms 1108 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 33 ms 6964 KB Output is correct
16 Correct 30 ms 7124 KB Output is correct
17 Correct 137 ms 8432 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 123 ms 32216 KB Output is correct
26 Correct 165 ms 32040 KB Output is correct
27 Correct 101 ms 30540 KB Output is correct
28 Incorrect 754 ms 15936 KB Output isn't correct
29 Halted 0 ms 0 KB -