Submission #123637

# Submission time Handle Problem Language Result Execution time Memory
123637 2019-07-01T20:56:09 Z duality Strange Device (APIO19_strange_device) C++11
100 / 100
668 ms 16996 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

LLI gcd(LLI a,LLI b) {
    LLI t;
    while (a > 0) t = b % a,b = a,a = t;
    return b;
}
vplli v;
int main() {
    int i;
    int n;
    LLI A,B,p,l,r;
    scanf("%d %lld %lld",&n,&A,&B);
    A /= gcd(A,B+1);
    if ((double) A*B > 2e18) p = 2e18;
    else p = A*B;
    for (i = 0; i < n; i++) {
        scanf("%lld %lld",&l,&r);
        if (r-l >= p) v.pb(mp(0,p-1));
        else {
            l %= p,r %= p;
            if (l <= r) v.pb(mp(l,r));
            else v.pb(mp(l,p-1)),v.pb(mp(0,r));
        }
    }

    LLI ans = p,m = 0;
    sort(v.begin(),v.end());
    for (i = 0; i < v.size(); i++) {
        if (v[i].first >= m) ans -= v[i].first-m;
        m = max(m,v[i].second+1);
    }
    ans -= p-m;
    printf("%lld\n",ans);

    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < v.size(); i++) {
                 ~~^~~~~~~~~~
strange_device.cpp:68: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:73: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 2 ms 256 KB Output is correct
2 Correct 8 ms 728 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 2 ms 296 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 256 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 256 KB Output is correct
11 Correct 2 ms 256 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 760 KB Output is correct
17 Correct 65 ms 2540 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 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 440 ms 16800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 588 ms 16928 KB Output is correct
3 Correct 569 ms 16936 KB Output is correct
4 Correct 548 ms 16972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 588 ms 16928 KB Output is correct
3 Correct 569 ms 16936 KB Output is correct
4 Correct 548 ms 16972 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 566 ms 16876 KB Output is correct
7 Correct 579 ms 16856 KB Output is correct
8 Correct 578 ms 16996 KB Output is correct
9 Correct 621 ms 16936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 588 ms 16928 KB Output is correct
3 Correct 569 ms 16936 KB Output is correct
4 Correct 548 ms 16972 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 58 ms 2540 KB Output is correct
7 Correct 61 ms 2560 KB Output is correct
8 Correct 55 ms 2472 KB Output is correct
9 Correct 57 ms 2552 KB Output is correct
10 Correct 57 ms 2536 KB Output is correct
11 Correct 60 ms 2508 KB Output is correct
12 Correct 55 ms 2540 KB Output is correct
13 Correct 60 ms 2536 KB Output is correct
14 Correct 58 ms 2540 KB Output is correct
15 Correct 63 ms 2488 KB Output is correct
16 Correct 63 ms 2536 KB Output is correct
17 Correct 58 ms 2532 KB Output is correct
18 Correct 583 ms 16880 KB Output is correct
19 Correct 561 ms 16976 KB Output is correct
20 Correct 615 ms 16900 KB Output is correct
21 Correct 62 ms 2536 KB Output is correct
22 Correct 53 ms 2548 KB Output is correct
23 Correct 208 ms 8672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 63 ms 2472 KB Output is correct
3 Correct 62 ms 2540 KB Output is correct
4 Correct 668 ms 16884 KB Output is correct
5 Correct 59 ms 2540 KB Output is correct
6 Correct 58 ms 2468 KB Output is correct
7 Correct 59 ms 2540 KB Output is correct
8 Correct 63 ms 2536 KB Output is correct
9 Correct 60 ms 2540 KB Output is correct
10 Correct 61 ms 2536 KB Output is correct
11 Correct 64 ms 2544 KB Output is correct
12 Correct 53 ms 2536 KB Output is correct
13 Correct 62 ms 2476 KB Output is correct
14 Correct 634 ms 16808 KB Output is correct
15 Correct 64 ms 2668 KB Output is correct
16 Correct 579 ms 16940 KB Output is correct
17 Correct 570 ms 16912 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 8 ms 728 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 2 ms 296 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 256 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 256 KB Output is correct
11 Correct 2 ms 256 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 760 KB Output is correct
17 Correct 65 ms 2540 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 252 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 3 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 440 ms 16800 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 588 ms 16928 KB Output is correct
31 Correct 569 ms 16936 KB Output is correct
32 Correct 548 ms 16972 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 566 ms 16876 KB Output is correct
35 Correct 579 ms 16856 KB Output is correct
36 Correct 578 ms 16996 KB Output is correct
37 Correct 621 ms 16936 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 58 ms 2540 KB Output is correct
40 Correct 61 ms 2560 KB Output is correct
41 Correct 55 ms 2472 KB Output is correct
42 Correct 57 ms 2552 KB Output is correct
43 Correct 57 ms 2536 KB Output is correct
44 Correct 60 ms 2508 KB Output is correct
45 Correct 55 ms 2540 KB Output is correct
46 Correct 60 ms 2536 KB Output is correct
47 Correct 58 ms 2540 KB Output is correct
48 Correct 63 ms 2488 KB Output is correct
49 Correct 63 ms 2536 KB Output is correct
50 Correct 58 ms 2532 KB Output is correct
51 Correct 583 ms 16880 KB Output is correct
52 Correct 561 ms 16976 KB Output is correct
53 Correct 615 ms 16900 KB Output is correct
54 Correct 62 ms 2536 KB Output is correct
55 Correct 53 ms 2548 KB Output is correct
56 Correct 208 ms 8672 KB Output is correct
57 Correct 2 ms 252 KB Output is correct
58 Correct 63 ms 2472 KB Output is correct
59 Correct 62 ms 2540 KB Output is correct
60 Correct 668 ms 16884 KB Output is correct
61 Correct 59 ms 2540 KB Output is correct
62 Correct 58 ms 2468 KB Output is correct
63 Correct 59 ms 2540 KB Output is correct
64 Correct 63 ms 2536 KB Output is correct
65 Correct 60 ms 2540 KB Output is correct
66 Correct 61 ms 2536 KB Output is correct
67 Correct 64 ms 2544 KB Output is correct
68 Correct 53 ms 2536 KB Output is correct
69 Correct 62 ms 2476 KB Output is correct
70 Correct 634 ms 16808 KB Output is correct
71 Correct 64 ms 2668 KB Output is correct
72 Correct 579 ms 16940 KB Output is correct
73 Correct 570 ms 16912 KB Output is correct
74 Correct 2 ms 252 KB Output is correct
75 Correct 2 ms 256 KB Output is correct
76 Correct 2 ms 256 KB Output is correct
77 Correct 2 ms 348 KB Output is correct
78 Correct 2 ms 256 KB Output is correct
79 Correct 8 ms 760 KB Output is correct
80 Correct 643 ms 16936 KB Output is correct
81 Correct 637 ms 16892 KB Output is correct
82 Correct 594 ms 16940 KB Output is correct
83 Correct 588 ms 16848 KB Output is correct
84 Correct 594 ms 16928 KB Output is correct
85 Correct 646 ms 16848 KB Output is correct
86 Correct 208 ms 8704 KB Output is correct
87 Correct 2 ms 256 KB Output is correct