답안 #710305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710305 2023-03-15T06:54:56 Z sharaelong Gap (APIO16_gap) C++17
100 / 100
60 ms 3180 KB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

ll findGap(int T, int n) {
    ll mn, mx;
    pair<ll, ll> range = { 0, 1000000000000000000ll };
    
    vector<ll> arr;
    if (T == 1) {
        for (int i=0; i<(n+1)/2; ++i) {
            MinMax(range.first, range.second, &mn, &mx);
            // cout << mn << ' ' << mx << endl;
            arr.push_back(mn);
            arr.push_back(mx);
            range = { mn+1, mx-1 };
        }
    } else {
        MinMax(range.first, range.second, &mn, &mx);
        arr.push_back(mn);
        arr.push_back(mx);

        ll d = (mx-mn-1) / (n-1);
        ll mn_cpy = mn, mx_cpy = mx;
        // cout << d << ' ' << mn << ' ' << mx << endl;
        for (int i=0; i<n-1; ++i) {
            // cout << mn_cpy+1 + (d+1)*i << ' ' << mn_cpy + (d+1)*(i+1) << endl;
            MinMax(mn_cpy+1 + (d+1)*i, mn_cpy + (d+1)*(i+1), &mn, &mx);
            if (mn != -1) {
                arr.push_back(mn);
                arr.push_back(mx);
            }
        }
    }
    
    sort(arr.begin(), arr.end());
    ll gap = 0;
    for (int i=0; i+1<arr.size(); ++i) gap = max(gap, arr[i+1]-arr[i]);
    // cout << endl;
    return gap;
}

Compilation message

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:26:25: warning: unused variable 'mx_cpy' [-Wunused-variable]
   26 |         ll mn_cpy = mn, mx_cpy = mx;
      |                         ^~~~~~
gap.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i=0; i+1<arr.size(); ++i) gap = max(gap, arr[i+1]-arr[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 1 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 260 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 336 KB Output is correct
16 Correct 9 ms 880 KB Output is correct
17 Correct 11 ms 848 KB Output is correct
18 Correct 10 ms 848 KB Output is correct
19 Correct 12 ms 896 KB Output is correct
20 Correct 9 ms 848 KB Output is correct
21 Correct 45 ms 2248 KB Output is correct
22 Correct 37 ms 2200 KB Output is correct
23 Correct 37 ms 2152 KB Output is correct
24 Correct 38 ms 2192 KB Output is correct
25 Correct 33 ms 2140 KB Output is correct
26 Correct 43 ms 2240 KB Output is correct
27 Correct 45 ms 2136 KB Output is correct
28 Correct 46 ms 2240 KB Output is correct
29 Correct 38 ms 2204 KB Output is correct
30 Correct 35 ms 2240 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 1 ms 332 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 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 348 KB Output is correct
16 Correct 13 ms 848 KB Output is correct
17 Correct 13 ms 896 KB Output is correct
18 Correct 14 ms 908 KB Output is correct
19 Correct 13 ms 912 KB Output is correct
20 Correct 7 ms 464 KB Output is correct
21 Correct 51 ms 2228 KB Output is correct
22 Correct 51 ms 2196 KB Output is correct
23 Correct 51 ms 2192 KB Output is correct
24 Correct 53 ms 2136 KB Output is correct
25 Correct 54 ms 3180 KB Output is correct
26 Correct 57 ms 2208 KB Output is correct
27 Correct 58 ms 2244 KB Output is correct
28 Correct 60 ms 2204 KB Output is correct
29 Correct 56 ms 2240 KB Output is correct
30 Correct 29 ms 1448 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct