답안 #934531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934531 2024-02-27T14:16:05 Z Rifal 이상한 기계 (APIO19_strange_device) C++14
65 / 100
534 ms 85988 KB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000000007
#define INF 1000000000
#define INF2 2000000000000000000
//#define ll long long
///#define cin fin
///#define cout fout
using namespace std;
double const EPS = 1e-14;
///ofstream fout("herding.out");
///ifstream fin("herding.in");

int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    long long n, a, b; cin >> n >> a >> b;
    pair<long long, long long> p[n];
    vector<pair<long long,int>> v;
    long long md = (a*b)/__gcd(a,b+1);
   // cout << n << ' ' << a << ' ' << b <<  endl;
   // cout << md << endl;
    bool ok = false;
    for(int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        //cout << i << endl;
        pair<long long, long long> pp;
        pp = p[i];
        p[i].first %= md;
        p[i].second %= md;
        if(p[i].second < p[i].first) {
            if(pp.second-pp.first+1 >= md) {
                cout << md << endl;
                ok = true;
            }
            v.push_back({p[i].first,0});
            v.push_back({md-1,1});
            v.push_back({0,0});
            v.push_back({p[i].second,1});
        }
        else {
            v.push_back({p[i].first,0});
            v.push_back({p[i].second,1});
        }
    }
    if(ok) return 0;
    sort(v.begin(),v.end()); int cnt = 0;
    long long l = -1, r = 0; 
    long long ans = 0;
    for(int i = 0; i < v.size(); i++) {
        if(v[i].second == 0) {
            cnt++;
            if(l == -1) l = v[i].first;
        }
        else {
            cnt--;
            r = max(v[i].first,r);
        }
        if(cnt == 0) {
            ans += r-l+1;
            l = -1, r = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = 0; i < v.size(); i++) {
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 1504 KB Output is correct
3 Correct 4 ms 1588 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 1624 KB Output is correct
17 Correct 56 ms 10528 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 259 ms 73020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 409 ms 85288 KB Output is correct
3 Correct 418 ms 84712 KB Output is correct
4 Correct 395 ms 85296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 409 ms 85288 KB Output is correct
3 Correct 418 ms 84712 KB Output is correct
4 Correct 395 ms 85296 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 421 ms 84504 KB Output is correct
7 Correct 403 ms 85988 KB Output is correct
8 Correct 416 ms 85884 KB Output is correct
9 Correct 470 ms 84644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 409 ms 85288 KB Output is correct
3 Correct 418 ms 84712 KB Output is correct
4 Correct 395 ms 85296 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 39 ms 10188 KB Output is correct
7 Correct 40 ms 9172 KB Output is correct
8 Correct 39 ms 10400 KB Output is correct
9 Correct 40 ms 9364 KB Output is correct
10 Correct 37 ms 10440 KB Output is correct
11 Correct 41 ms 9416 KB Output is correct
12 Correct 37 ms 10200 KB Output is correct
13 Correct 46 ms 9280 KB Output is correct
14 Correct 40 ms 9660 KB Output is correct
15 Correct 48 ms 8904 KB Output is correct
16 Correct 45 ms 9780 KB Output is correct
17 Correct 43 ms 9416 KB Output is correct
18 Correct 419 ms 85260 KB Output is correct
19 Correct 391 ms 85748 KB Output is correct
20 Correct 490 ms 84728 KB Output is correct
21 Correct 46 ms 10696 KB Output is correct
22 Correct 34 ms 9708 KB Output is correct
23 Correct 106 ms 33460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 44 ms 9588 KB Output is correct
3 Correct 45 ms 9856 KB Output is correct
4 Correct 534 ms 84448 KB Output is correct
5 Correct 54 ms 10188 KB Output is correct
6 Correct 46 ms 10480 KB Output is correct
7 Correct 43 ms 9420 KB Output is correct
8 Correct 45 ms 10688 KB Output is correct
9 Correct 42 ms 9680 KB Output is correct
10 Correct 45 ms 10196 KB Output is correct
11 Correct 51 ms 10740 KB Output is correct
12 Correct 39 ms 9416 KB Output is correct
13 Correct 45 ms 9396 KB Output is correct
14 Correct 468 ms 84648 KB Output is correct
15 Correct 46 ms 10196 KB Output is correct
16 Correct 372 ms 84644 KB Output is correct
17 Correct 403 ms 84768 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 1504 KB Output is correct
3 Correct 4 ms 1588 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 1624 KB Output is correct
17 Correct 56 ms 10528 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Incorrect 1 ms 600 KB Output isn't correct
21 Halted 0 ms 0 KB -