답안 #535502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535502 2022-03-10T11:47:05 Z byunjaewoo Gap (APIO16_gap) C++17
100 / 100
67 ms 2764 KB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#include "gap.h"

ll findGap(int T, int N) {
    if(T==1) {
        ll res=0, s=-1, e=(ll)1e18+1;
        vector<ll> V;
        for(int i=1; i<=(N+1)/2; i++) {
            MinMax(s+1, e-1, &s, &e);
            V.push_back(s);
            if(s!=e) V.push_back(e);
        }
        sort(V.begin(), V.end());
        for(int i=0; i<V.size()-1; i++) res=max(res, V[i+1]-V[i]);
        return res;
    }
    ll s, e, res=0;
    MinMax(0, (ll)1e18, &s, &e);
    res=e-s;
    if(N==2) return res;
    s++, e--;
    ll d=(e-s+1)/N;
    ll l, r=s-1;
    vector<ll> a, b;
    for(ll i=1; i<=N+1; i++) {
        l=r+1, r=min(e, l+d);
        if(l>r) continue;
        ll x, y;
        MinMax(l, r, &x, &y);
        if(x!=-1) {
            a.push_back(x);
            b.push_back(y);
        }
    }
    if(a.size()) res=max(a[0]-s+1, e-b.back()+1);
    for(int i=0; i<a.size()-1; i++) res=max(res, a[i+1]-b[i]);
    return res;
}

Compilation message

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         for(int i=0; i<V.size()-1; i++) res=max(res, V[i+1]-V[i]);
      |                      ~^~~~~~~~~~~
gap.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0; i<a.size()-1; i++) res=max(res, a[i+1]-b[i]);
      |                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 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 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 352 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 900 KB Output is correct
17 Correct 11 ms 856 KB Output is correct
18 Correct 12 ms 800 KB Output is correct
19 Correct 11 ms 848 KB Output is correct
20 Correct 8 ms 848 KB Output is correct
21 Correct 42 ms 2164 KB Output is correct
22 Correct 40 ms 2228 KB Output is correct
23 Correct 49 ms 2244 KB Output is correct
24 Correct 48 ms 2204 KB Output is correct
25 Correct 36 ms 2184 KB Output is correct
26 Correct 44 ms 2204 KB Output is correct
27 Correct 55 ms 2200 KB Output is correct
28 Correct 43 ms 2240 KB Output is correct
29 Correct 49 ms 2228 KB Output is correct
30 Correct 35 ms 2224 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 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 1 ms 208 KB Output is correct
4 Correct 1 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 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 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 15 ms 852 KB Output is correct
17 Correct 13 ms 764 KB Output is correct
18 Correct 14 ms 848 KB Output is correct
19 Correct 13 ms 808 KB Output is correct
20 Correct 7 ms 532 KB Output is correct
21 Correct 56 ms 2212 KB Output is correct
22 Correct 52 ms 2196 KB Output is correct
23 Correct 55 ms 2204 KB Output is correct
24 Correct 57 ms 2196 KB Output is correct
25 Correct 55 ms 2764 KB Output is correct
26 Correct 61 ms 2172 KB Output is correct
27 Correct 53 ms 2180 KB Output is correct
28 Correct 53 ms 2116 KB Output is correct
29 Correct 67 ms 2132 KB Output is correct
30 Correct 36 ms 1332 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct