Submission #126546

# Submission time Handle Problem Language Result Execution time Memory
126546 2019-07-08T04:14:58 Z DodgeBallMan Strange Device (APIO19_strange_device) C++14
100 / 100
675 ms 42304 KB
#include <bits/stdc++.h>
#define pll pair<long long, long long>
#define x first
#define y second

using namespace std;

const long long inf = 1000000000000000000;
int n;
long long a, b, ans, sum;
vector<pll> seg, m;

int chk( long long a, long long b ) {
    long long temp;
    temp = inf / a;
    if( b > temp ) return 1;
    else return 0 ;
}

void process( long long mul ) {
    //cout << mul << endl;
    for( int i = 1 ; i < ( int )seg.size() ; i++ ) {
        if( seg[i].y - seg[i].x + 1 >= mul ) {
            printf("%lld",mul);
            return ;
        }
        long long f = seg[i].x % mul, t = seg[i].y % mul;
        if( t < f ) m.emplace_back( pll( f, mul - 1 ) ), m.emplace_back( pll( 0, t ) );
        else m.emplace_back( pll( f, t ) );
    }
    sort( m.begin(), m.end() );
    long long l = -1, r = -1;
    for( int i = 0 ; i < m.size() ; i++ ) {
        //printf("%lld %lld\n",m[i].x,m[i].y);
        if( m[i].x > r ) {
            ans += m[i].y - m[i].x + 1;
            l = m[i].x, r = m[i].y;
        }
        else {
            ans += ( m[i].y - m[i].x + 1 ) - ( min( r, m[i].y ) - max( l, m[i].x ) + 1 );
            r = max( r, m[i].y );
        }
    }
    printf("%lld",ans);
    return ;
}

int main()
{
    scanf("%d %lld %lld",&n,&a,&b);
    seg.emplace_back( pll( -1LL, -1LL ) );
    for( int i = 1 ; i <= n ; i++ ) {
        long long ff, tt;
        scanf("%lld %lld",&ff,&tt);
        seg.emplace_back( pll( ff, tt ) );
        sum += tt - ff + 1;
    }
    long long g = __gcd( a, b + 1 );
    long long x = a / g;
    int cc = chk( x, b );
    if( cc ) return !printf("%lld",sum);
    process( x*b );
    return 0;
}

Compilation message

strange_device.cpp: In function 'void process(long long int)':
strange_device.cpp:33:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i = 0 ; i < m.size() ; i++ ) {
                      ~~^~~~~~~~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:50: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:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld",&ff,&tt);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 8 ms 1272 KB Output is correct
3 Correct 15 ms 1240 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 292 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 276 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 8 ms 1268 KB Output is correct
17 Correct 69 ms 6348 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 458 ms 42304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 609 ms 42176 KB Output is correct
3 Correct 588 ms 41396 KB Output is correct
4 Correct 574 ms 41288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 609 ms 42176 KB Output is correct
3 Correct 588 ms 41396 KB Output is correct
4 Correct 574 ms 41288 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 583 ms 41312 KB Output is correct
7 Correct 605 ms 41224 KB Output is correct
8 Correct 590 ms 41216 KB Output is correct
9 Correct 636 ms 41328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 609 ms 42176 KB Output is correct
3 Correct 588 ms 41396 KB Output is correct
4 Correct 574 ms 41288 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 62 ms 6916 KB Output is correct
7 Correct 65 ms 6364 KB Output is correct
8 Correct 60 ms 6400 KB Output is correct
9 Correct 61 ms 6376 KB Output is correct
10 Correct 62 ms 6400 KB Output is correct
11 Correct 66 ms 6644 KB Output is correct
12 Correct 65 ms 6612 KB Output is correct
13 Correct 67 ms 6628 KB Output is correct
14 Correct 60 ms 6636 KB Output is correct
15 Correct 67 ms 6628 KB Output is correct
16 Correct 68 ms 6816 KB Output is correct
17 Correct 63 ms 6692 KB Output is correct
18 Correct 605 ms 41296 KB Output is correct
19 Correct 579 ms 41252 KB Output is correct
20 Correct 635 ms 41148 KB Output is correct
21 Correct 64 ms 6500 KB Output is correct
22 Correct 56 ms 6412 KB Output is correct
23 Correct 222 ms 19796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 68 ms 6500 KB Output is correct
3 Correct 66 ms 6144 KB Output is correct
4 Correct 654 ms 41300 KB Output is correct
5 Correct 64 ms 6428 KB Output is correct
6 Correct 64 ms 6372 KB Output is correct
7 Correct 66 ms 6348 KB Output is correct
8 Correct 67 ms 6372 KB Output is correct
9 Correct 66 ms 6372 KB Output is correct
10 Correct 64 ms 6388 KB Output is correct
11 Correct 67 ms 6324 KB Output is correct
12 Correct 57 ms 6432 KB Output is correct
13 Correct 65 ms 6380 KB Output is correct
14 Correct 651 ms 41508 KB Output is correct
15 Correct 66 ms 6500 KB Output is correct
16 Correct 598 ms 41316 KB Output is correct
17 Correct 596 ms 41320 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 8 ms 1272 KB Output is correct
3 Correct 15 ms 1240 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 292 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 276 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 8 ms 1268 KB Output is correct
17 Correct 69 ms 6348 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 458 ms 42304 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 609 ms 42176 KB Output is correct
31 Correct 588 ms 41396 KB Output is correct
32 Correct 574 ms 41288 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 583 ms 41312 KB Output is correct
35 Correct 605 ms 41224 KB Output is correct
36 Correct 590 ms 41216 KB Output is correct
37 Correct 636 ms 41328 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 62 ms 6916 KB Output is correct
40 Correct 65 ms 6364 KB Output is correct
41 Correct 60 ms 6400 KB Output is correct
42 Correct 61 ms 6376 KB Output is correct
43 Correct 62 ms 6400 KB Output is correct
44 Correct 66 ms 6644 KB Output is correct
45 Correct 65 ms 6612 KB Output is correct
46 Correct 67 ms 6628 KB Output is correct
47 Correct 60 ms 6636 KB Output is correct
48 Correct 67 ms 6628 KB Output is correct
49 Correct 68 ms 6816 KB Output is correct
50 Correct 63 ms 6692 KB Output is correct
51 Correct 605 ms 41296 KB Output is correct
52 Correct 579 ms 41252 KB Output is correct
53 Correct 635 ms 41148 KB Output is correct
54 Correct 64 ms 6500 KB Output is correct
55 Correct 56 ms 6412 KB Output is correct
56 Correct 222 ms 19796 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 68 ms 6500 KB Output is correct
59 Correct 66 ms 6144 KB Output is correct
60 Correct 654 ms 41300 KB Output is correct
61 Correct 64 ms 6428 KB Output is correct
62 Correct 64 ms 6372 KB Output is correct
63 Correct 66 ms 6348 KB Output is correct
64 Correct 67 ms 6372 KB Output is correct
65 Correct 66 ms 6372 KB Output is correct
66 Correct 64 ms 6388 KB Output is correct
67 Correct 67 ms 6324 KB Output is correct
68 Correct 57 ms 6432 KB Output is correct
69 Correct 65 ms 6380 KB Output is correct
70 Correct 651 ms 41508 KB Output is correct
71 Correct 66 ms 6500 KB Output is correct
72 Correct 598 ms 41316 KB Output is correct
73 Correct 596 ms 41320 KB Output is correct
74 Correct 2 ms 256 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 256 KB Output is correct
78 Correct 3 ms 376 KB Output is correct
79 Correct 8 ms 1268 KB Output is correct
80 Correct 660 ms 41200 KB Output is correct
81 Correct 652 ms 41152 KB Output is correct
82 Correct 620 ms 41452 KB Output is correct
83 Correct 618 ms 41288 KB Output is correct
84 Correct 623 ms 41256 KB Output is correct
85 Correct 675 ms 41244 KB Output is correct
86 Correct 222 ms 19544 KB Output is correct
87 Correct 2 ms 348 KB Output is correct