Submission #370795

# Submission time Handle Problem Language Result Execution time Memory
370795 2021-02-24T16:17:58 Z cpp219 Strange Device (APIO19_strange_device) C++14
100 / 100
566 ms 69308 KB
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e6 + 3;
const ll inf = 1e18 + 7;
LL a[N];
ll n,A,B,q,total;
vector<LL> v;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>n>>A>>B; q = A/__gcd(B + 1,A);
    if (inf / B < q) total = inf;
    else total = q * B; //cout<<total; return 0;
    for (ll i = 1;i <= n;i++){
        cin>>a[i].fs>>a[i].sc;
        if (a[i].sc - a[i].fs + 1 >= total) v.push_back({0,total - 1});
        else{
            a[i].fs %= total; a[i].sc %= total;
            if (a[i].fs <= a[i].sc) v.push_back(a[i]);
            else{
                v.push_back({0,a[i].sc}); v.push_back({a[i].fs,total - 1});
            }
        }
    }
    sort(v.begin(),v.end());
    ll mx = -inf,ans = 0;
    for (auto i : v){
        if (i.sc <= mx) continue;
        if (i.fs > mx) ans += i.sc - i.fs + 1;
        else ans += max(0ll,i.sc - mx);
        mx = max(mx,i.sc);
    }
    cout<<ans;
}

Compilation message

strange_device.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
strange_device.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
strange_device.cpp: In function 'int main()':
strange_device.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 5 ms 876 KB Output is correct
3 Correct 5 ms 876 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 51 ms 3704 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 331 ms 31804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 466 ms 32056 KB Output is correct
3 Correct 492 ms 31804 KB Output is correct
4 Correct 456 ms 31816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 466 ms 32056 KB Output is correct
3 Correct 492 ms 31804 KB Output is correct
4 Correct 456 ms 31816 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 473 ms 31936 KB Output is correct
7 Correct 482 ms 31804 KB Output is correct
8 Correct 461 ms 31804 KB Output is correct
9 Correct 537 ms 32056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 466 ms 32056 KB Output is correct
3 Correct 492 ms 31804 KB Output is correct
4 Correct 456 ms 31816 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 46 ms 3560 KB Output is correct
7 Correct 99 ms 3684 KB Output is correct
8 Correct 45 ms 3560 KB Output is correct
9 Correct 46 ms 3560 KB Output is correct
10 Correct 46 ms 3560 KB Output is correct
11 Correct 48 ms 3560 KB Output is correct
12 Correct 45 ms 3560 KB Output is correct
13 Correct 49 ms 3560 KB Output is correct
14 Correct 45 ms 3560 KB Output is correct
15 Correct 52 ms 3560 KB Output is correct
16 Correct 50 ms 3560 KB Output is correct
17 Correct 46 ms 3560 KB Output is correct
18 Correct 469 ms 31956 KB Output is correct
19 Correct 453 ms 31804 KB Output is correct
20 Correct 517 ms 31804 KB Output is correct
21 Correct 74 ms 3560 KB Output is correct
22 Correct 65 ms 3560 KB Output is correct
23 Correct 142 ms 12892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 59 ms 3560 KB Output is correct
3 Correct 50 ms 3560 KB Output is correct
4 Correct 547 ms 31740 KB Output is correct
5 Correct 49 ms 3560 KB Output is correct
6 Correct 49 ms 3560 KB Output is correct
7 Correct 49 ms 3560 KB Output is correct
8 Correct 50 ms 3560 KB Output is correct
9 Correct 48 ms 3560 KB Output is correct
10 Correct 50 ms 3560 KB Output is correct
11 Correct 78 ms 3560 KB Output is correct
12 Correct 43 ms 3560 KB Output is correct
13 Correct 49 ms 3560 KB Output is correct
14 Correct 535 ms 31804 KB Output is correct
15 Correct 49 ms 3560 KB Output is correct
16 Correct 463 ms 31804 KB Output is correct
17 Correct 462 ms 31804 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 5 ms 876 KB Output is correct
3 Correct 5 ms 876 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 51 ms 3704 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 0 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 331 ms 31804 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 466 ms 32056 KB Output is correct
31 Correct 492 ms 31804 KB Output is correct
32 Correct 456 ms 31816 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 473 ms 31936 KB Output is correct
35 Correct 482 ms 31804 KB Output is correct
36 Correct 461 ms 31804 KB Output is correct
37 Correct 537 ms 32056 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 46 ms 3560 KB Output is correct
40 Correct 99 ms 3684 KB Output is correct
41 Correct 45 ms 3560 KB Output is correct
42 Correct 46 ms 3560 KB Output is correct
43 Correct 46 ms 3560 KB Output is correct
44 Correct 48 ms 3560 KB Output is correct
45 Correct 45 ms 3560 KB Output is correct
46 Correct 49 ms 3560 KB Output is correct
47 Correct 45 ms 3560 KB Output is correct
48 Correct 52 ms 3560 KB Output is correct
49 Correct 50 ms 3560 KB Output is correct
50 Correct 46 ms 3560 KB Output is correct
51 Correct 469 ms 31956 KB Output is correct
52 Correct 453 ms 31804 KB Output is correct
53 Correct 517 ms 31804 KB Output is correct
54 Correct 74 ms 3560 KB Output is correct
55 Correct 65 ms 3560 KB Output is correct
56 Correct 142 ms 12892 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 59 ms 3560 KB Output is correct
59 Correct 50 ms 3560 KB Output is correct
60 Correct 547 ms 31740 KB Output is correct
61 Correct 49 ms 3560 KB Output is correct
62 Correct 49 ms 3560 KB Output is correct
63 Correct 49 ms 3560 KB Output is correct
64 Correct 50 ms 3560 KB Output is correct
65 Correct 48 ms 3560 KB Output is correct
66 Correct 50 ms 3560 KB Output is correct
67 Correct 78 ms 3560 KB Output is correct
68 Correct 43 ms 3560 KB Output is correct
69 Correct 49 ms 3560 KB Output is correct
70 Correct 535 ms 31804 KB Output is correct
71 Correct 49 ms 3560 KB Output is correct
72 Correct 463 ms 31804 KB Output is correct
73 Correct 462 ms 31804 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 5 ms 1260 KB Output is correct
80 Correct 549 ms 69052 KB Output is correct
81 Correct 566 ms 69308 KB Output is correct
82 Correct 563 ms 69180 KB Output is correct
83 Correct 541 ms 69064 KB Output is correct
84 Correct 527 ms 69212 KB Output is correct
85 Correct 522 ms 69052 KB Output is correct
86 Correct 145 ms 23768 KB Output is correct
87 Correct 1 ms 364 KB Output is correct