Submission #222270

# Submission time Handle Problem Language Result Execution time Memory
222270 2020-04-12T21:07:55 Z Bruteforceman Gap (APIO16_gap) C++11
100 / 100
85 ms 3316 KB
#include "bits/stdc++.h"
#include "gap.h"
using namespace std;
const long long maxV = 1e18;

long long findGap(int T, int N)
{       
    long long mx, mn;
    MinMax(0, maxV, &mn, &mx);
    if(T == 1) {
        vector <long long> left, right;
        left.push_back(mn); right.push_back(mx);
        while(left.size() + right.size() < N) {
            long long p, q;
            MinMax(mn + 1, mx - 1, &p, &q);
            tie(mn, mx) = make_pair(p, q);
            left.push_back(mn);
            right.push_back(mx);
        }
        for(auto i : right) left.push_back(i);
        sort(left.begin(), left.end());
        long long ans = 0;
        for(int i = 1; i < left.size(); i++) {
            ans = max(ans, left[i] - left[i - 1]);
        }
        return ans;
    }
    long long lower = (mx - mn + N - 2) / (N - 1);
    long long cur = mn + 1;
    vector <long long> v ({mn});
    int cnt = N - 1; 
    while(cur <= mx) {
        long long p, q;
        MinMax(cur, min(mx, cur + lower), &p, &q);    
        cur += lower + 1;
        if(p != -1) {
            if(!v.empty()) {
                lower = max(lower, p - v.back());
            }
            v.push_back(p);
            v.push_back(q);
            cnt -= (p == q) ? 1 : 2;
        } else {
            lower = max(lower, min(mx, cur) - v.back());
        }
        if(cnt) lower = max(lower, (mx - v.back() + cnt - 1) / cnt);
        // cout << cur << " " << min(mx, cur + lower - 1) << " " << p << " " << q << endl;
    }
	return lower;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:13:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(left.size() + right.size() < N) {
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
gap.cpp:23:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 1; i < left.size(); i++) {
                        ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 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 4 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 5 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 18 ms 1024 KB Output is correct
17 Correct 18 ms 1024 KB Output is correct
18 Correct 18 ms 1024 KB Output is correct
19 Correct 18 ms 1024 KB Output is correct
20 Correct 14 ms 1024 KB Output is correct
21 Correct 70 ms 2628 KB Output is correct
22 Correct 64 ms 2716 KB Output is correct
23 Correct 85 ms 2712 KB Output is correct
24 Correct 61 ms 2716 KB Output is correct
25 Correct 56 ms 2716 KB Output is correct
26 Correct 69 ms 2648 KB Output is correct
27 Correct 61 ms 2656 KB Output is correct
28 Correct 72 ms 2716 KB Output is correct
29 Correct 61 ms 2716 KB Output is correct
30 Correct 46 ms 2716 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 304 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 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 5 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 13 ms 640 KB Output is correct
17 Correct 14 ms 640 KB Output is correct
18 Correct 13 ms 640 KB Output is correct
19 Correct 14 ms 640 KB Output is correct
20 Correct 8 ms 512 KB Output is correct
21 Correct 38 ms 1512 KB Output is correct
22 Correct 46 ms 1492 KB Output is correct
23 Correct 40 ms 1472 KB Output is correct
24 Correct 39 ms 1528 KB Output is correct
25 Correct 67 ms 3316 KB Output is correct
26 Correct 39 ms 1484 KB Output is correct
27 Correct 39 ms 1504 KB Output is correct
28 Correct 38 ms 1528 KB Output is correct
29 Correct 40 ms 1656 KB Output is correct
30 Correct 21 ms 1280 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct