Submission #81800

# Submission time Handle Problem Language Result Execution time Memory
81800 2018-10-26T17:08:18 Z xiaowuc1 Gap (APIO16_gap) C++14
100 / 100
113 ms 19964 KB
#include <bits/stdc++.h>
#include "gap.h"
 
using namespace std;
 
typedef long long ll;
 
ll onesolve(int n) {
  ll lhs, rhs;
  MinMax(0, 1000000000000000000LL, &lhs, &rhs);
  set<ll> all;
  all.insert(lhs);
  all.insert(rhs);
  n -= 2;
  while(n > 0) {
    MinMax(lhs+1, rhs-1, &lhs, &rhs);
      all.insert(lhs);
  all.insert(rhs);
    n -= 2;
  }
  ll ret = 0;
  ll lowest = *all.begin();
	for(ll out: all) {
		ret = max(ret, out - lowest);
		lowest = out;
	}
	return ret;
}
 
ll twosolve(int n) {
	ll lhs, rhs;
	MinMax(0, 1000000000000000000LL, &lhs, &rhs);
	ll ret = (rhs-lhs+n-2)/(n-1);
	ll endend = rhs;
	// printf("initial guess %lld\n", ret);
	set<ll> all;
	all.insert(lhs);
	all.insert(rhs);
	ll last = lhs+1;
	while(last <= endend) {
		MinMax(last, last + ret, &lhs, &rhs);
		// printf("%lld %lld %lld %lld\n", last, last+ret, lhs, rhs);
		if(lhs >= 0) {
			all.insert(lhs);
			all.insert(rhs);
		}
		last += ret+1;
	}
	ll lowest = *all.begin();
	for(ll out: all) {
		ret = max(ret, out - lowest);
		lowest = out;
	}
	return ret;
}
 
ll findGap(int t, int n) {
	if(t==1) return onesolve(n);
	else return twosolve(n);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Correct 2 ms 612 KB Output is correct
7 Correct 2 ms 612 KB Output is correct
8 Correct 2 ms 612 KB Output is correct
9 Correct 2 ms 612 KB Output is correct
10 Correct 2 ms 612 KB Output is correct
11 Correct 3 ms 660 KB Output is correct
12 Correct 3 ms 660 KB Output is correct
13 Correct 3 ms 660 KB Output is correct
14 Correct 4 ms 660 KB Output is correct
15 Correct 3 ms 660 KB Output is correct
16 Correct 21 ms 2484 KB Output is correct
17 Correct 21 ms 2836 KB Output is correct
18 Correct 21 ms 3300 KB Output is correct
19 Correct 20 ms 3776 KB Output is correct
20 Correct 17 ms 3984 KB Output is correct
21 Correct 86 ms 9900 KB Output is correct
22 Correct 84 ms 11716 KB Output is correct
23 Correct 86 ms 13200 KB Output is correct
24 Correct 84 ms 13200 KB Output is correct
25 Correct 76 ms 14256 KB Output is correct
26 Correct 88 ms 16100 KB Output is correct
27 Correct 95 ms 17940 KB Output is correct
28 Correct 85 ms 19888 KB Output is correct
29 Correct 82 ms 19964 KB Output is correct
30 Correct 75 ms 19964 KB Output is correct
31 Correct 2 ms 19964 KB Output is correct
32 Correct 2 ms 19964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 19964 KB Output is correct
2 Correct 2 ms 19964 KB Output is correct
3 Correct 2 ms 19964 KB Output is correct
4 Correct 2 ms 19964 KB Output is correct
5 Correct 2 ms 19964 KB Output is correct
6 Correct 2 ms 19964 KB Output is correct
7 Correct 2 ms 19964 KB Output is correct
8 Correct 2 ms 19964 KB Output is correct
9 Correct 2 ms 19964 KB Output is correct
10 Correct 2 ms 19964 KB Output is correct
11 Correct 3 ms 19964 KB Output is correct
12 Correct 3 ms 19964 KB Output is correct
13 Correct 3 ms 19964 KB Output is correct
14 Correct 3 ms 19964 KB Output is correct
15 Correct 4 ms 19964 KB Output is correct
16 Correct 25 ms 19964 KB Output is correct
17 Correct 28 ms 19964 KB Output is correct
18 Correct 26 ms 19964 KB Output is correct
19 Correct 29 ms 19964 KB Output is correct
20 Correct 10 ms 19964 KB Output is correct
21 Correct 105 ms 19964 KB Output is correct
22 Correct 107 ms 19964 KB Output is correct
23 Correct 110 ms 19964 KB Output is correct
24 Correct 108 ms 19964 KB Output is correct
25 Correct 113 ms 19964 KB Output is correct
26 Correct 112 ms 19964 KB Output is correct
27 Correct 109 ms 19964 KB Output is correct
28 Correct 106 ms 19964 KB Output is correct
29 Correct 106 ms 19964 KB Output is correct
30 Correct 43 ms 19964 KB Output is correct
31 Correct 3 ms 19964 KB Output is correct
32 Correct 3 ms 19964 KB Output is correct