Submission #126595

# Submission time Handle Problem Language Result Execution time Memory
126595 2019-07-08T07:20:01 Z jakob_nogler Gap (APIO16_gap) C++14
100 / 100
75 ms 3308 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

typedef long long ll;
typedef vector<ll> vll;

const ll inf = 1e18;

ll findGap(int T, int N){
	ll lo, hi, t_lo, t_hi, ans = 1, cnt = 2;
	MinMax(0, inf, &lo, &hi);

	if(N == 2) return hi - lo;
	if(T == 1){
		while(lo < hi){
			t_lo = lo, t_hi = hi;
			if(cnt == N){
				ans = max(ans, hi - lo);
				break;
			}
			if(lo + 1 >= hi - 1) break;
			MinMax(lo + 1, hi - 1, &lo, &hi);
			ans = max(ans, t_hi - hi);
			ans = max(ans, lo - t_lo);
			cnt += 2;
		}

		return ans;
	}

	vll vec;
	ll amm = (hi - lo) / (N - 2);
	//cout << amm << endl;

	vec.push_back(lo);
	ll id = lo + 1;
	while(true){
		MinMax(id, id + amm, &t_lo, &t_hi);
		//cout << id << " " << id + amm << " " << t_lo << " " << t_hi << endl;
		if(t_lo != - 1){
			vec.push_back(t_lo);
			vec.push_back(t_hi);
		}
		if(id + amm + 1 >= hi) break;
		id += amm + 1;
	}
	vec.push_back(hi);

	for(int i = 0; i < vec.size() - 1; i++)
		ans = max(ans, vec[i + 1] - vec[i]);
	return ans;
}

Compilation message

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < vec.size() - 1; i++)
                 ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 3 ms 380 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 15 ms 1016 KB Output is correct
17 Correct 15 ms 1016 KB Output is correct
18 Correct 16 ms 1016 KB Output is correct
19 Correct 15 ms 1016 KB Output is correct
20 Correct 11 ms 760 KB Output is correct
21 Correct 54 ms 2940 KB Output is correct
22 Correct 54 ms 3036 KB Output is correct
23 Correct 54 ms 3032 KB Output is correct
24 Correct 55 ms 3064 KB Output is correct
25 Correct 46 ms 2296 KB Output is correct
26 Correct 54 ms 2936 KB Output is correct
27 Correct 54 ms 2936 KB Output is correct
28 Correct 54 ms 2936 KB Output is correct
29 Correct 57 ms 2936 KB Output is correct
30 Correct 40 ms 1912 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 400 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 19 ms 888 KB Output is correct
17 Correct 19 ms 1016 KB Output is correct
18 Correct 19 ms 888 KB Output is correct
19 Correct 19 ms 888 KB Output is correct
20 Correct 10 ms 632 KB Output is correct
21 Correct 74 ms 2288 KB Output is correct
22 Correct 74 ms 2288 KB Output is correct
23 Correct 75 ms 2260 KB Output is correct
24 Correct 74 ms 2288 KB Output is correct
25 Correct 70 ms 3308 KB Output is correct
26 Correct 75 ms 2284 KB Output is correct
27 Correct 75 ms 2284 KB Output is correct
28 Correct 74 ms 2416 KB Output is correct
29 Correct 75 ms 2284 KB Output is correct
30 Correct 38 ms 1528 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct