Submission #131786

# Submission time Handle Problem Language Result Execution time Memory
131786 2019-07-17T16:01:07 Z junodeveloper Gap (APIO16_gap) C++14
100 / 100
82 ms 2416 KB
#include "gap.h"
#include <vector>
#include <algorithm>
using namespace std;
 
long long findGap(int T, int N) {
	long long s, e, mn, mx, res = 0;
	if(T == 1) {
		s=0, e=1e18;
		vector<long long> v;
		while(s <= e && N > 0) {
			MinMax(s, e, &mn, &mx);
			if(mn == -1) break;
			v.push_back(mn), N--;
			if(mn != mx) v.push_back(mx), N--;
			s = mn + 1, e = mx - 1;
		}
		sort(v.begin(), v.end());
		for(int i=0; i+1<v.size(); i++)
			res = max(res, v[i+1] - v[i]);
	} else {
		s=0, e=1e18;
		MinMax(s, e, &mn, &mx);
		long long len = (mx - mn + N - 2) / (N - 1);
		vector<long long> v;
		s=mn, e=mx;
		while(s <= e) {
			MinMax(s, s + len, &mn, &mx);
			if(mn != -1) {
				v.push_back(mn);
				if(mn != mx) v.push_back(mx);
			}
			s += len + 1;
		}
		sort(v.begin(), v.end());
		res = len;
		for(int i=0; i+1<v.size(); i++)
			res = max(res, v[i+1] - v[i]);
	}
	return res;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:19:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i+1<v.size(); i++)
                ~~~^~~~~~~~~
gap.cpp:37:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i+1<v.size(); i++)
                ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 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 17 ms 888 KB Output is correct
17 Correct 16 ms 888 KB Output is correct
18 Correct 16 ms 888 KB Output is correct
19 Correct 17 ms 888 KB Output is correct
20 Correct 13 ms 888 KB Output is correct
21 Correct 61 ms 2288 KB Output is correct
22 Correct 61 ms 2284 KB Output is correct
23 Correct 61 ms 2288 KB Output is correct
24 Correct 62 ms 2416 KB Output is correct
25 Correct 54 ms 2296 KB Output is correct
26 Correct 64 ms 2260 KB Output is correct
27 Correct 63 ms 2236 KB Output is correct
28 Correct 61 ms 2256 KB Output is correct
29 Correct 61 ms 2288 KB Output is correct
30 Correct 47 ms 2288 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 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 248 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 348 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 20 ms 888 KB Output is correct
17 Correct 20 ms 888 KB Output is correct
18 Correct 20 ms 888 KB Output is correct
19 Correct 21 ms 860 KB Output is correct
20 Correct 9 ms 504 KB Output is correct
21 Correct 79 ms 2288 KB Output is correct
22 Correct 81 ms 2288 KB Output is correct
23 Correct 82 ms 2300 KB Output is correct
24 Correct 80 ms 2288 KB Output is correct
25 Correct 76 ms 2208 KB Output is correct
26 Correct 80 ms 2260 KB Output is correct
27 Correct 79 ms 2288 KB Output is correct
28 Correct 80 ms 2288 KB Output is correct
29 Correct 80 ms 2268 KB Output is correct
30 Correct 37 ms 1528 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct