Submission #370787

# Submission time Handle Problem Language Result Execution time Memory
370787 2021-02-24T15:36:20 Z cpp219 Strange Device (APIO19_strange_device) C++14
65 / 100
530 ms 32076 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;
    for (ll i = 1;i <= n;i++){
        cin>>a[i].fs>>a[i].sc;
        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 0 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 1 ms 364 KB Output is correct
6 Correct 0 ms 364 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 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 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 3560 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 354 ms 31932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 461 ms 31828 KB Output is correct
3 Correct 452 ms 32076 KB Output is correct
4 Correct 436 ms 31804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 461 ms 31828 KB Output is correct
3 Correct 452 ms 32076 KB Output is correct
4 Correct 436 ms 31804 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 450 ms 31804 KB Output is correct
7 Correct 451 ms 31932 KB Output is correct
8 Correct 442 ms 31884 KB Output is correct
9 Correct 493 ms 31932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 461 ms 31828 KB Output is correct
3 Correct 452 ms 32076 KB Output is correct
4 Correct 436 ms 31804 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 43 ms 3560 KB Output is correct
7 Correct 50 ms 3560 KB Output is correct
8 Correct 44 ms 3560 KB Output is correct
9 Correct 44 ms 3560 KB Output is correct
10 Correct 44 ms 3560 KB Output is correct
11 Correct 46 ms 3560 KB Output is correct
12 Correct 46 ms 3684 KB Output is correct
13 Correct 46 ms 3560 KB Output is correct
14 Correct 43 ms 3568 KB Output is correct
15 Correct 49 ms 3560 KB Output is correct
16 Correct 47 ms 3560 KB Output is correct
17 Correct 44 ms 3560 KB Output is correct
18 Correct 456 ms 31828 KB Output is correct
19 Correct 438 ms 31804 KB Output is correct
20 Correct 499 ms 31808 KB Output is correct
21 Correct 48 ms 3560 KB Output is correct
22 Correct 43 ms 3560 KB Output is correct
23 Correct 143 ms 12764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 49 ms 3560 KB Output is correct
3 Correct 48 ms 3560 KB Output is correct
4 Correct 530 ms 31804 KB Output is correct
5 Correct 47 ms 3560 KB Output is correct
6 Correct 56 ms 3560 KB Output is correct
7 Correct 49 ms 3560 KB Output is correct
8 Correct 48 ms 3560 KB Output is correct
9 Correct 47 ms 3684 KB Output is correct
10 Correct 47 ms 3560 KB Output is correct
11 Correct 48 ms 3560 KB Output is correct
12 Correct 43 ms 3560 KB Output is correct
13 Correct 48 ms 3728 KB Output is correct
14 Correct 494 ms 31804 KB Output is correct
15 Correct 46 ms 3560 KB Output is correct
16 Correct 449 ms 31900 KB Output is correct
17 Correct 442 ms 31932 KB Output is correct
18 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 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 1 ms 364 KB Output is correct
6 Correct 0 ms 364 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 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 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 3560 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Incorrect 0 ms 364 KB Output isn't correct
21 Halted 0 ms 0 KB -