답안 #366561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366561 2021-02-14T14:00:15 Z Nima_Naderi 이상한 기계 (APIO19_strange_device) C++14
20 / 100
1148 ms 128084 KB
///In the name of GOD
//#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 1e6 + 10;
const ll INF = 1e18;
ll n, A, B, g, k, m;
ll L[MXN], R[MXN], cnt[MXN];
vector<ll> Num;
vector<pair<ll, ll>> seg;
inline int GetId(ll x){
    return lower_bound(Num.begin(), Num.end(), x) - Num.begin();
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n >> A >> B;
    g = __gcd(A, B + 1);
    k = (A / g);
    m = (k > (INF + B - 1) / B ? INF + 1 : k * B);
    for(int i = 1; i <= n; i ++){
        cin >> L[i] >> R[i];
        if(R[i] - L[i] + 1 >= m) return cout << m, 0;
        L[i] %= m, R[i] %= m;
        Num.push_back(L[i]), Num.push_back(R[i]), Num.push_back(R[i] + 1);
        if(R[i] < L[i]){
            seg.push_back({L[i], m - 1});
            seg.push_back({0, R[i]});
        }
        else{
            seg.push_back({L[i], R[i]});
        }
    }
    Num.push_back(0), Num.push_back(m - 1);
    Num.push_back(1), Num.push_back(m);
    sort(Num.begin(), Num.end());
    Num.resize(unique(Num.begin(), Num.end()) - Num.begin());
    sort(seg.begin(), seg.end());
    for(auto LR : seg){
        ll l, r; tie(l, r) = LR;
        cnt[GetId(l)] ++, cnt[GetId(r + 1)] --;
    }
    ll ans = 0, bal = 0, len;
    for(int i = 0; i < Num.size() - 1; i ++){
        len = (Num[i + 1] - 1) - Num[i] + 1;
        bal += cnt[i];
        assert(bal >= 0);
        if(bal > 0) ans += len;
    }
    cout << ans << '\n';
    return 0;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i = 0; i < Num.size() - 1; i ++){
      |                    ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 1256 KB Output is correct
3 Correct 9 ms 1256 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 0 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 1256 KB Output is correct
17 Correct 105 ms 7376 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 498 ms 55392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 878 ms 63344 KB Output is correct
3 Correct 959 ms 63376 KB Output is correct
4 Runtime error 935 ms 128084 KB Execution killed with signal 6
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 878 ms 63344 KB Output is correct
3 Correct 959 ms 63376 KB Output is correct
4 Runtime error 935 ms 128084 KB Execution killed with signal 6
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 878 ms 63344 KB Output is correct
3 Correct 959 ms 63376 KB Output is correct
4 Runtime error 935 ms 128084 KB Execution killed with signal 6
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 98 ms 7584 KB Output is correct
3 Correct 103 ms 7732 KB Output is correct
4 Incorrect 1148 ms 63216 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 1256 KB Output is correct
3 Correct 9 ms 1256 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 0 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 1256 KB Output is correct
17 Correct 105 ms 7376 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 498 ms 55392 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 878 ms 63344 KB Output is correct
31 Correct 959 ms 63376 KB Output is correct
32 Runtime error 935 ms 128084 KB Execution killed with signal 6