Submission #203828

# Submission time Handle Problem Language Result Execution time Memory
203828 2020-02-22T11:52:27 Z georgerapeanu Strange Device (APIO19_strange_device) C++11
20 / 100
708 ms 69016 KB
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n;
long long a,b;

vector<pair<long long,int> > events;

long long gcd(long long a,long long b){
    if(b == 0){
        return a;
    }
    return gcd(b,a % b);
}

int main(){

    scanf("%d %lld %lld",&n,&a,&b);

    a /= gcd(a,b + 1);

    vector<pair<long long,long long> > segm;

    for(int i = 1;i <= n;i++){
        long long l,r;
        scanf("%lld %lld",&l,&r);

        if((r - l + 1) / a >= b){
            printf("%lld\n",a * b);
            return 0;
        }

        long long fst = (((l / b) % a) * (b) + (l % b));
        long long snd = (((r / b) % a) * (b) + (r % b));

        if(fst > snd){
            events.push_back({fst,1});
            events.push_back({(a - 1) * (b) + (b - 1) + 1,-1});
            events.push_back({0,1});
            events.push_back({snd + 1,-1});
        }
        else{
            events.push_back({fst,1});
            events.push_back({snd + 1,-1});
        }
    }

    sort(events.begin(),events.end());

    long long ans = 0;
    int lst = -1;
    int cnt_active = 0;

    for(auto it:events){
        ans += ((long long)(cnt_active > 0)) * (it.first - lst);
        lst = it.first;
        cnt_active += it.second;
    }

    printf("%lld\n",ans);

    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld %lld",&n,&a,&b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld",&l,&r);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 11 ms 1392 KB Output is correct
3 Correct 12 ms 1396 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 12 ms 1268 KB Output is correct
17 Correct 81 ms 7268 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 509 ms 56944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 689 ms 68992 KB Output is correct
3 Incorrect 708 ms 69016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 689 ms 68992 KB Output is correct
3 Incorrect 708 ms 69016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 689 ms 68992 KB Output is correct
3 Incorrect 708 ms 69016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 80 ms 7320 KB Output is correct
3 Incorrect 79 ms 7268 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 11 ms 1392 KB Output is correct
3 Correct 12 ms 1396 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 12 ms 1268 KB Output is correct
17 Correct 81 ms 7268 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 4 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 509 ms 56944 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 689 ms 68992 KB Output is correct
31 Incorrect 708 ms 69016 KB Output isn't correct
32 Halted 0 ms 0 KB -