답안 #556459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556459 2022-05-03T07:49:47 Z SavicS Gap (APIO16_gap) C++17
100 / 100
60 ms 3216 KB
#include "gap.h"
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ldb;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ldb,ldb> pdd;
 
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(a) (int)(a).size()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)
 
const int mod = 1000000007;
const ll inf = 1e18;
const int mxN = 200005; 
 
int N;
 
ll findGap(int T, int _N){
    N = _N;

    if(T == 1){

        ll P = 0, Z = 0; 
        MinMax(0, inf, &P, &Z);

        vector<ll> vec; vec.pb(P); vec.pb(Z);
        ff(i,1,(N - 1) / 2){
            ll S = 0, Q = 0;
            MinMax(P + 1, Z - 1, &S, &Q);
            vec.pb(S); vec.pb(Q);
            P = S; Z = Q;
        }

        sort(all(vec));

        ll mx = 0;
        ff(i,1,sz(vec) - 1)mx = max(mx, vec[i] - vec[i - 1]);
        return mx;

    }
    else{

        ll P = 0, Z = 0; 
        MinMax(0, inf, &P, &Z);
     
        if(N == 2){
            return Z - P;
        }
     
        ll D = (Z - P - 1 + N - 2) / (N - 1);
     
        vector<ll> vec; vec.pb(P);
        for(ll X = P + 1; X < Z; X += D){
            ll L = X;
            ll R = min(Z - 1, X + D - 1);
     
            ll S = 0, Q = 0;
            MinMax(L, R, &S, &Q);
     
            if(S != -1)vec.pb(S);
            if(Q != -1)vec.pb(Q);
     
        }

        vec.pb(Z);
     
        ll mx = 0;
        ff(i,1,sz(vec) - 1){
            mx = max(mx, vec[i] - vec[i - 1]);
        }
     
        return mx;

    }
 
}
 
 
// int main() {
//     cin.tie(0)->sync_with_stdio(0);
 
//     cin >> N;
//     ff(i,1,N)cin >> A[i];
 
//     cout << findGap(1, N) << '\n';
 
//     return 0;
// }
/*
 
4
2 3 6 8
 
// probati bojenje sahovski
*/
 
 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 11 ms 848 KB Output is correct
17 Correct 11 ms 860 KB Output is correct
18 Correct 10 ms 848 KB Output is correct
19 Correct 12 ms 904 KB Output is correct
20 Correct 9 ms 848 KB Output is correct
21 Correct 43 ms 2368 KB Output is correct
22 Correct 41 ms 2212 KB Output is correct
23 Correct 42 ms 2240 KB Output is correct
24 Correct 51 ms 2244 KB Output is correct
25 Correct 41 ms 2156 KB Output is correct
26 Correct 42 ms 2244 KB Output is correct
27 Correct 42 ms 2240 KB Output is correct
28 Correct 43 ms 2236 KB Output is correct
29 Correct 45 ms 2212 KB Output is correct
30 Correct 36 ms 2260 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 13 ms 848 KB Output is correct
17 Correct 14 ms 848 KB Output is correct
18 Correct 12 ms 820 KB Output is correct
19 Correct 12 ms 928 KB Output is correct
20 Correct 6 ms 464 KB Output is correct
21 Correct 53 ms 2216 KB Output is correct
22 Correct 55 ms 2236 KB Output is correct
23 Correct 55 ms 2212 KB Output is correct
24 Correct 57 ms 2228 KB Output is correct
25 Correct 49 ms 3216 KB Output is correct
26 Correct 58 ms 2208 KB Output is correct
27 Correct 52 ms 2224 KB Output is correct
28 Correct 52 ms 2160 KB Output is correct
29 Correct 60 ms 2208 KB Output is correct
30 Correct 37 ms 1452 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct