Submission #229642

# Submission time Handle Problem Language Result Execution time Memory
229642 2020-05-05T14:25:43 Z davooddkareshki Strange Device (APIO19_strange_device) C++17
5 / 100
545 ms 53608 KB
// be name khoda
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
//#define mp make_pair 
typedef long long ll;
#define int long long
#pragma GCC optimize("Ofast")

const int maxn = 2e5+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;
//const int N = 2e6+10;

int n, m, A, B;

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin>> n >> A >> B;
    m = A / __gcd(A,B+1);
    if(m <= inf/B) m *= B;
    else m = inf;

    vector<pair<int,int>> seg;
    for(int i = 1, l, r; i <= n; i++)
    {
        cin>> l >> r;
        if(r-l+1 >= m) return cout<< m, 0;
        l %= m; r %= m;
        if(l <= r)
            seg.push_back({l,r});            
        else
        {
            seg.push_back({l,m-1});
            seg.push_back({0,r});
        }
    }
    sort(seg.begin(), seg.end());

    ll ans = 0, mx = -1;
    for(int i = 0; i < seg.size(); i++)
    {
        int l = seg[i].F, r = seg[i].S;
        //cout<< l <<" "<< r <<"\n";
        mx = max(mx,l-1);
        ans += r-mx;
        mx = max(mx,r);
    }
    cout<< ans;
}
/*
3 3 3
4 4
7 9
17 18

3 5 10
1 20
50 68
89 98

2 16 13
2 5
18 18
*/

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:46:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < seg.size(); i++)
                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 10 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 545 ms 53608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 545 ms 53608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 545 ms 53608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 61 ms 5728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 10 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -