답안 #343164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343164 2021-01-03T13:06:31 Z jjwdi0 Gap (APIO16_gap) C++11
100 / 100
67 ms 3484 KB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve1(int N) {
    int x = (N + 1) / 2;
    vector<ll> v;
    ll s = 0, e = 1e18, mn, mx;
    for(int i=0; i<x; i++) {
        MinMax(s, e, &mn, &mx);
        v.push_back(mn);
        if(mn != mx) v.push_back(mx);
        s = mn + 1, e = mx - 1;
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    for(int i=1; i<N; i++) {
        ans = max(ans, v[i] - v[i-1]);
    }
    return ans;
}

ll solve2(int N) {
    ll s = 0, e = 1e18, mn, mx;
    MinMax(s, e, &mn, &mx);
    s = mn, e = mx;
    ll T = (e - s + N - 2) / (N - 1);
    vector<ll> v;
    ll l = s, r = s + T;
    for(int i=1; i<N; i++) {
        MinMax(l, r, &mn, &mx);
        if(mn != -1) v.push_back(mn), v.push_back(mx);
        l += T + 1, r += T + 1;
    }
    ll ans = 0;
    for(int i=1; i<v.size(); i++) {
        ans = max(ans, v[i] - v[i-1]);
    }
    return ans;
}

ll findGap(int T, int N) {
    if(T == 1) return solve1(N);
    return solve2(N);
}

Compilation message

gap.cpp: In function 'll solve2(int)':
gap.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=1; i<v.size(); i++) {
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 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
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 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 12 ms 876 KB Output is correct
17 Correct 12 ms 876 KB Output is correct
18 Correct 12 ms 876 KB Output is correct
19 Correct 12 ms 876 KB Output is correct
20 Correct 10 ms 884 KB Output is correct
21 Correct 48 ms 2316 KB Output is correct
22 Correct 48 ms 2276 KB Output is correct
23 Correct 49 ms 2276 KB Output is correct
24 Correct 49 ms 2276 KB Output is correct
25 Correct 43 ms 2276 KB Output is correct
26 Correct 48 ms 2276 KB Output is correct
27 Correct 51 ms 2284 KB Output is correct
28 Correct 49 ms 2276 KB Output is correct
29 Correct 47 ms 2276 KB Output is correct
30 Correct 40 ms 2276 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 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 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 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 17 ms 876 KB Output is correct
17 Correct 15 ms 876 KB Output is correct
18 Correct 15 ms 932 KB Output is correct
19 Correct 15 ms 876 KB Output is correct
20 Correct 7 ms 492 KB Output is correct
21 Correct 67 ms 2276 KB Output is correct
22 Correct 61 ms 2404 KB Output is correct
23 Correct 61 ms 2276 KB Output is correct
24 Correct 62 ms 2276 KB Output is correct
25 Correct 62 ms 3484 KB Output is correct
26 Correct 60 ms 2276 KB Output is correct
27 Correct 60 ms 2276 KB Output is correct
28 Correct 62 ms 2404 KB Output is correct
29 Correct 61 ms 2276 KB Output is correct
30 Correct 37 ms 1644 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct