답안 #395544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395544 2021-04-28T13:24:35 Z jeroenodb Gap (APIO16_gap) C++14
100 / 100
77 ms 3256 KB
#include "gap.h"
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
const int mxN = 1e5+1;
const ll oo = 1e18;
long long findGap(int T, int N)
{
	ll amax,amin;
	MinMax(0,oo,&amin,&amax);
	if(T==1) {
		ll ans = 0;
		int left = N-2;
		vector<ll> a = {amin,amax};
		while(left>0) {
			MinMax(amin+1,amax-1,&amin,&amax);
			left-=2;
			a.push_back(amin);
			if(amax!=amin) a.push_back(amax);
		}
		sort(all(a));
		for(int i=1;i<N;++i) {
			ans = max(ans,a[i]-a[i-1]);
		}
		return ans;
	}
	ll ans = (amax-amin+N-2) / (N-1);
	// invariant: low contains a value, range [low+1, low+ans] can't contain answer
	ll low = amin+1;
	vector<pl> groups = {{amin,amin}};
	while(low<amax) {
		ll l,r; MinMax(low,min(amax-1,low+ans),&l,&r);
		low += ans+1;
		if(l==-1) {
			continue;
		}
		groups.push_back({l,r});
		
	}
	groups.push_back({amax,amax});
	for(int i=1;i<(int)groups.size();++i) {
		ans = max(ans, groups[i].first - groups[i-1].second);
	}
	return ans;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 2 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 14 ms 852 KB Output is correct
17 Correct 14 ms 840 KB Output is correct
18 Correct 13 ms 840 KB Output is correct
19 Correct 13 ms 852 KB Output is correct
20 Correct 10 ms 840 KB Output is correct
21 Correct 52 ms 2184 KB Output is correct
22 Correct 51 ms 2128 KB Output is correct
23 Correct 52 ms 2188 KB Output is correct
24 Correct 50 ms 2232 KB Output is correct
25 Correct 45 ms 2224 KB Output is correct
26 Correct 50 ms 2232 KB Output is correct
27 Correct 50 ms 2168 KB Output is correct
28 Correct 57 ms 2244 KB Output is correct
29 Correct 51 ms 2172 KB Output is correct
30 Correct 45 ms 2184 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 1 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 2 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 15 ms 840 KB Output is correct
17 Correct 15 ms 840 KB Output is correct
18 Correct 16 ms 860 KB Output is correct
19 Correct 15 ms 840 KB Output is correct
20 Correct 9 ms 492 KB Output is correct
21 Correct 64 ms 2252 KB Output is correct
22 Correct 64 ms 2232 KB Output is correct
23 Correct 77 ms 2232 KB Output is correct
24 Correct 70 ms 2148 KB Output is correct
25 Correct 60 ms 3256 KB Output is correct
26 Correct 64 ms 2140 KB Output is correct
27 Correct 64 ms 2204 KB Output is correct
28 Correct 65 ms 2184 KB Output is correct
29 Correct 64 ms 2188 KB Output is correct
30 Correct 32 ms 1380 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 1 ms 200 KB Output is correct