Submission #586634

# Submission time Handle Problem Language Result Execution time Memory
586634 2022-06-30T13:13:03 Z GioChkhaidze Gap (APIO16_gap) C++14
100 / 100
58 ms 3536 KB
#include "gap.h"
#include <bits/stdc++.h>

#define ll long long
#define pb push_back

using namespace std;

const int Nn = 1e5 + 5;

ll a[Nn];

long long findGap(int T, int N) {
	ll ans = 0;
	if (T == 1) {
		ll Mn = -1, Mx = -1, l = 0, r = N - 1;
		MinMax(0ll, 1000000000000000000ll, &Mn, &Mx);
		a[l] = Mn, a[r] = Mx;
		while (l + 1 < r) {
			MinMax(a[l] + 1, a[r] - 1, &Mn, &Mx);
			if (Mn == -1 && Mx == -1) {
				break;
			}
			a[++l] = Mn;
			a[--r] = Mx;
		}
		for (int i = 1; i < N; ++i) {
			ans = max(ans, a[i] - a[i - 1]);
		}		
	}
		else
	if (T == 2) {
		vector < ll > s;
		ll Mn = -1, Mx = -1, l = 0, r = N - 1;
		MinMax(0ll, 1000000000000000000ll, &Mn, &Mx);
		ll A = Mn, B = Mx;
		ll len = (Mx - Mn + 1 + N - 1) / N;
		s.pb(A);
		for (ll i = A; i < B; i += len) {
			MinMax(i + 1, min(i + len, B - 1), &Mn, &Mx);
			if (Mn == -1 && Mx == -1) continue;
			s.pb(Mn), s.pb(Mx);
		}
		s.pb(B);
		for (int i = 1; i < s.size(); ++i) {
			ans = max(ans, s[i] - s[i - 1]);
		} 
	}
	return ans;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int i = 1; i < s.size(); ++i) {
      |                   ~~^~~~~~~~~~
gap.cpp:34:24: warning: unused variable 'l' [-Wunused-variable]
   34 |   ll Mn = -1, Mx = -1, l = 0, r = N - 1;
      |                        ^
gap.cpp:34:31: warning: unused variable 'r' [-Wunused-variable]
   34 |   ll Mn = -1, Mx = -1, l = 0, r = N - 1;
      |                               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 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 1 ms 208 KB Output is correct
6 Correct 0 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 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 336 KB Output is correct
16 Correct 9 ms 628 KB Output is correct
17 Correct 8 ms 700 KB Output is correct
18 Correct 8 ms 604 KB Output is correct
19 Correct 8 ms 696 KB Output is correct
20 Correct 7 ms 712 KB Output is correct
21 Correct 34 ms 1828 KB Output is correct
22 Correct 33 ms 1832 KB Output is correct
23 Correct 37 ms 1864 KB Output is correct
24 Correct 35 ms 1832 KB Output is correct
25 Correct 29 ms 1736 KB Output is correct
26 Correct 36 ms 1792 KB Output is correct
27 Correct 36 ms 1788 KB Output is correct
28 Correct 33 ms 1828 KB Output is correct
29 Correct 33 ms 1828 KB Output is correct
30 Correct 31 ms 1848 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 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 336 KB Output is correct
16 Correct 12 ms 848 KB Output is correct
17 Correct 12 ms 908 KB Output is correct
18 Correct 12 ms 848 KB Output is correct
19 Correct 12 ms 848 KB Output is correct
20 Correct 6 ms 464 KB Output is correct
21 Correct 51 ms 2240 KB Output is correct
22 Correct 48 ms 2324 KB Output is correct
23 Correct 50 ms 2208 KB Output is correct
24 Correct 57 ms 2244 KB Output is correct
25 Correct 52 ms 3536 KB Output is correct
26 Correct 50 ms 2140 KB Output is correct
27 Correct 49 ms 2240 KB Output is correct
28 Correct 48 ms 2216 KB Output is correct
29 Correct 58 ms 2192 KB Output is correct
30 Correct 27 ms 1452 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct