Submission #934423

# Submission time Handle Problem Language Result Execution time Memory
934423 2024-02-27T10:08:17 Z Rifal Strange Device (APIO19_strange_device) C++14
0 / 100
422 ms 50724 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;
    for(int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        p[i].first *= 2ll;
        p[i].second *= 2ll;
        pair<long long, long long> pp;
        pp = p[i];
        p[i].first %= a;
        p[i].second %= a;
        if(p[i].second < p[i].first) {
            if(pp.second-pp.first+1 >= a) {
                cout << a << endl; return 0;
            }
            v.push_back({p[i].first,0});
            v.push_back({a-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});
        }
    }
    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:46: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]
   46 |     for(int i = 0; i < v.size(); i++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 4 ms 1248 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Incorrect 422 ms 50724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Incorrect 422 ms 50724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Incorrect 422 ms 50724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 1884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 4 ms 1248 KB Output isn't correct
3 Halted 0 ms 0 KB -