Submission #753828

# Submission time Handle Problem Language Result Execution time Memory
753828 2023-06-06T06:48:13 Z bgnbvnbv Strange Device (APIO19_strange_device) C++14
35 / 100
499 ms 53296 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,A,B;
vector<pli>vec;
void solve()
{
    cin >> n >> A >> B;
    ll x=(A/__gcd(A,B+1)) * B;
    bool ok=true;
    for(int i=1;i<=n;i++)
    {
        ll l,r;
        cin >> l >> r;
        if((r-l+1)>=x)
        {
            ok=false;
        }
        l%=x;
        r%=x;
        if(l<=r)
        {
            vec.pb({l,r});
        }
        else
        {
            vec.pb({l,x-1});
            vec.pb({0,r});
        }
    }
    if(ok==false)
    {
        cout << x;
        return;
    }
    sort(vec.begin(),vec.end());
    ll ans=0;
    for(int i=0;i<vec.size();i++)
    {
        ll j=i+1;
        ll r=vec[i].se;
        while(j<vec.size()&&vec[j].fi<=r)
        {
            r=max(r,vec[j].se);
            j++;
        }
        ans+=r-vec[i].fi+1;
        i=j-1;
    }
    cout << ans;
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i=0;i<vec.size();i++)
      |                 ~^~~~~~~~~~~
strange_device.cpp:51:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         while(j<vec.size()&&vec[j].fi<=r)
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1060 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 984 KB Output is correct
17 Correct 48 ms 5692 KB Output is correct
18 Incorrect 1 ms 324 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 288 ms 17544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 430 ms 53212 KB Output is correct
3 Correct 416 ms 53288 KB Output is correct
4 Correct 421 ms 42436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 430 ms 53212 KB Output is correct
3 Correct 416 ms 53288 KB Output is correct
4 Correct 421 ms 42436 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 431 ms 42532 KB Output is correct
7 Correct 412 ms 42612 KB Output is correct
8 Correct 415 ms 42620 KB Output is correct
9 Correct 471 ms 42832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 430 ms 53212 KB Output is correct
3 Correct 416 ms 53288 KB Output is correct
4 Correct 421 ms 42436 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 40 ms 5700 KB Output is correct
7 Correct 49 ms 5632 KB Output is correct
8 Correct 44 ms 5632 KB Output is correct
9 Correct 40 ms 5648 KB Output is correct
10 Correct 47 ms 5668 KB Output is correct
11 Correct 41 ms 5796 KB Output is correct
12 Correct 39 ms 5676 KB Output is correct
13 Correct 42 ms 5684 KB Output is correct
14 Correct 39 ms 5720 KB Output is correct
15 Correct 43 ms 5704 KB Output is correct
16 Correct 48 ms 5616 KB Output is correct
17 Correct 40 ms 5680 KB Output is correct
18 Correct 420 ms 42968 KB Output is correct
19 Correct 427 ms 43580 KB Output is correct
20 Correct 499 ms 53296 KB Output is correct
21 Correct 42 ms 5696 KB Output is correct
22 Correct 40 ms 5732 KB Output is correct
23 Correct 139 ms 18464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 46 ms 5696 KB Output is correct
3 Correct 45 ms 5600 KB Output is correct
4 Correct 467 ms 23448 KB Output is correct
5 Correct 41 ms 5688 KB Output is correct
6 Correct 44 ms 5640 KB Output is correct
7 Correct 45 ms 5668 KB Output is correct
8 Correct 55 ms 5648 KB Output is correct
9 Correct 46 ms 5700 KB Output is correct
10 Correct 44 ms 5720 KB Output is correct
11 Correct 44 ms 5628 KB Output is correct
12 Correct 39 ms 5700 KB Output is correct
13 Correct 43 ms 5684 KB Output is correct
14 Correct 464 ms 23244 KB Output is correct
15 Correct 43 ms 5684 KB Output is correct
16 Correct 424 ms 43596 KB Output is correct
17 Correct 441 ms 43780 KB Output is correct
18 Incorrect 1 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1060 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 984 KB Output is correct
17 Correct 48 ms 5692 KB Output is correct
18 Incorrect 1 ms 324 KB Output isn't correct
19 Halted 0 ms 0 KB -