Submission #720369

# Submission time Handle Problem Language Result Execution time Memory
720369 2023-04-08T05:33:00 Z joelgun14 Gap (APIO16_gap) C++17
100 / 100
47 ms 3232 KB
#include "gap.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;

long long findGap(int T, int N)
{
	// can call findmax function
	// let's say range is between 1 to 1e18
	// divide n into blocks size n / k
	if(T == 1) {
		ll l = 0, r = 1e18;
		ll a[N];
		for(int i = 0; i < N / 2 + N % 2; ++i) {
			MinMax(l, r, &a[i], &a[N - i - 1]);
			l = a[i] + 1, r = a[N - i - 1] - 1;
		}
		ll mxdiff = 0;
		for(int i = 1; i < N; ++i)
			mxdiff = max(mxdiff, a[i] - a[i - 1]);
		return mxdiff;
	}
	else {
		// divide N blocks size len / N into blocks
		ll l, r;
		MinMax((ll)0, (ll)1e18, &l, &r);
		if(N == 2)
			return r - l;
		ll minres = (r - l + N - 2) / (ll)(N - 1);
		// kita query dr l + 1 ke l + min_res
		// n - 1 query total n elem?
		vector<ll> x = {l};
		ll a, b;
		__int128 crl = l + 1 ,crr = l + minres + 1;
		for(int i = 0; i < N - 1; ++i) {
			MinMax(min((ll)crl, (ll)r - 1), min((ll)crr, (ll)r - 1), &a, &b);
			crl += minres + 1;
			if(a != -1) {
				minres = max(minres, a - x.back());
				x.push_back(a), x.push_back(b);
			}
			crr = crl + minres;
			if(crl >= r)
				break;
		}
		x.push_back(r);
		ll res = 0;
		for(int i = 1; i < x.size(); ++i)
			res = max(res, x[i] - x[i - 1]);
		return res;
	}
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for(int i = 1; i < x.size(); ++i)
      |                  ~~^~~~~~~~~~
# 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 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 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 592 KB Output is correct
17 Correct 9 ms 592 KB Output is correct
18 Correct 9 ms 604 KB Output is correct
19 Correct 8 ms 636 KB Output is correct
20 Correct 8 ms 592 KB Output is correct
21 Correct 34 ms 1872 KB Output is correct
22 Correct 43 ms 1836 KB Output is correct
23 Correct 35 ms 1736 KB Output is correct
24 Correct 41 ms 1764 KB Output is correct
25 Correct 35 ms 1796 KB Output is correct
26 Correct 37 ms 1860 KB Output is correct
27 Correct 36 ms 1824 KB Output is correct
28 Correct 36 ms 1832 KB Output is correct
29 Correct 37 ms 1820 KB Output is correct
30 Correct 30 ms 1836 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 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 1 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 1 ms 208 KB Output is correct
7 Correct 1 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 0 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 6 ms 592 KB Output is correct
17 Correct 8 ms 548 KB Output is correct
18 Correct 6 ms 592 KB Output is correct
19 Correct 6 ms 592 KB Output is correct
20 Correct 5 ms 464 KB Output is correct
21 Correct 21 ms 1480 KB Output is correct
22 Correct 28 ms 1468 KB Output is correct
23 Correct 25 ms 1368 KB Output is correct
24 Correct 28 ms 1444 KB Output is correct
25 Correct 47 ms 3232 KB Output is correct
26 Correct 22 ms 1492 KB Output is correct
27 Correct 24 ms 1444 KB Output is correct
28 Correct 28 ms 1572 KB Output is correct
29 Correct 33 ms 1444 KB Output is correct
30 Correct 21 ms 1136 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct