답안 #238092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238092 2020-06-09T22:11:50 Z DS007 Gap (APIO16_gap) C++14
100 / 100
90 ms 5984 KB
#include <bits/stdc++.h>
using namespace std;
#include "gap.h"
 
long long solve1(int n) {
    set<long long> s;
    long long l = 0, h = 1e18;
    while (s.size() != n) {
        long long mn = -1, mx = -1;
        MinMax(l, h, &mn, &mx);
        l = mn + 1, h = mx - 1;
        s.insert(mn);
        s.insert(mx);
    }
 
    long long last = 1e18, ans = 0;
    for (auto i : s) {
        ans = max(ans, i - last);
        last = i;
    }
 
    return ans;
}
 
long long solve2(int n) {
    long long mn = -1, mx = -1, l = 0, h = 1e18, tm1 = -1, tm2 = -1;
    MinMax(l, h, &mn, &mx);
 
    if (n == 2)
        return mx - mn;
 
    long long m = (mx - mn) / (n - 1), last = mn, ans = m;
    for (long long i = mn; i < mx; i += m + 1) {
        MinMax(i, i + m, &tm1, &tm2);
        ans = max(ans, tm1 - last);
        last = max(last, tm2);
    }
 
    return ans;
}
 
long long findGap(int t, int n) {
    if (t == 1)
        return solve1(n);
    else
        return solve2(n);
}

Compilation message

gap.cpp: In function 'long long int solve1(int)':
gap.cpp:8:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (s.size() != n) {
            ~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 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 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 512 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 21 ms 1744 KB Output is correct
17 Correct 24 ms 1664 KB Output is correct
18 Correct 22 ms 1664 KB Output is correct
19 Correct 22 ms 1656 KB Output is correct
20 Correct 17 ms 1664 KB Output is correct
21 Correct 76 ms 5776 KB Output is correct
22 Correct 84 ms 5840 KB Output is correct
23 Correct 81 ms 5876 KB Output is correct
24 Correct 79 ms 5836 KB Output is correct
25 Correct 73 ms 5780 KB Output is correct
26 Correct 87 ms 5948 KB Output is correct
27 Correct 83 ms 5928 KB Output is correct
28 Correct 90 ms 5880 KB Output is correct
29 Correct 87 ms 5884 KB Output is correct
30 Correct 65 ms 5984 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 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 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 4 ms 384 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 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 19 ms 512 KB Output is correct
17 Correct 20 ms 588 KB Output is correct
18 Correct 20 ms 512 KB Output is correct
19 Correct 21 ms 512 KB Output is correct
20 Correct 12 ms 512 KB Output is correct
21 Correct 69 ms 1076 KB Output is correct
22 Correct 68 ms 1144 KB Output is correct
23 Correct 70 ms 1144 KB Output is correct
24 Correct 69 ms 1144 KB Output is correct
25 Correct 61 ms 1144 KB Output is correct
26 Correct 71 ms 1144 KB Output is correct
27 Correct 70 ms 1144 KB Output is correct
28 Correct 71 ms 1128 KB Output is correct
29 Correct 68 ms 1104 KB Output is correct
30 Correct 37 ms 1152 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 512 KB Output is correct