Submission #230260

# Submission time Handle Problem Language Result Execution time Memory
230260 2020-05-09T12:20:27 Z mat_v Gap (APIO16_gap) C++14
100 / 100
81 ms 3308 KB
#include "gap.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
 
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
 
 
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
 
long long findGap(int t, int n){
    if(t == 1){
        ll l = 0;
        ll r = 1000000000;
        r *= r;
        vector<ll>svi;
        while(l <= r){
            if(svi.size() == n)break;
            ll mn,mx;
            MinMax(l,r,&mn,&mx);
            if(mn == -1 || mx == -1)break;
            svi.pb(mx);
            if(mn != mx)svi.pb(mn);
            l = mn+1;
            r = mx-1;
        }
        sort(svi.begin(), svi.end());
        ll res = 0;
        n = svi.size();
        ff(i,1,n - 1){
            res = max(res, svi[i] - svi[i - 1]);
        }
        return res;
    }
    else if(t == 2){
        ll mn,mx;
        ll l = 0;
        ll r = 1000000000;
        r *= r;
        vector<ll> svi;
        MinMax(l,r,&mn,&mx);
        svi.pb(mn);
        svi.pb(mx);
 
        ll dif = mx - mn;
        dif /= (n-1);
        if(! (mx%(n-1) == mn%(n-1)))dif++;
        if(dif == 0){
            return mx - mn;
        }
        for(ll i = mn+1; i<=mx-1; i+=dif){
            //if(svi.size() == n)break;
            ll p1,p2;
            MinMax(i,i+dif-1,&p1,&p2);
            if(p1 == -1 || p2 == -1)continue;
            svi.pb(p1);
            svi.pb(p2);
        }
        sort(svi.begin(), svi.end());
        ll res = 0;
        n = svi.size();
        ff(i,1,n - 1){
            res = max(res, svi[i] - svi[i - 1]);
        }
        return res;
    }
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:30:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(svi.size() == n)break;
                ~~~~~~~~~~~^~~~
gap.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 18 ms 1024 KB Output is correct
17 Correct 17 ms 896 KB Output is correct
18 Correct 17 ms 896 KB Output is correct
19 Correct 17 ms 896 KB Output is correct
20 Correct 13 ms 1024 KB Output is correct
21 Correct 56 ms 2288 KB Output is correct
22 Correct 57 ms 2288 KB Output is correct
23 Correct 64 ms 2336 KB Output is correct
24 Correct 59 ms 2288 KB Output is correct
25 Correct 55 ms 2288 KB Output is correct
26 Correct 57 ms 2280 KB Output is correct
27 Correct 60 ms 2288 KB Output is correct
28 Correct 56 ms 2416 KB Output is correct
29 Correct 57 ms 2356 KB Output is correct
30 Correct 40 ms 2288 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 20 ms 1024 KB Output is correct
17 Correct 21 ms 896 KB Output is correct
18 Correct 20 ms 896 KB Output is correct
19 Correct 21 ms 1024 KB Output is correct
20 Correct 13 ms 688 KB Output is correct
21 Correct 74 ms 2348 KB Output is correct
22 Correct 81 ms 2288 KB Output is correct
23 Correct 75 ms 2288 KB Output is correct
24 Correct 72 ms 2280 KB Output is correct
25 Correct 72 ms 3308 KB Output is correct
26 Correct 72 ms 2288 KB Output is correct
27 Correct 72 ms 2288 KB Output is correct
28 Correct 71 ms 2288 KB Output is correct
29 Correct 71 ms 2288 KB Output is correct
30 Correct 38 ms 1528 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct