답안 #30811

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30811 2017-07-26T14:59:01 Z cdemirer Gap (APIO16_gap) C++14
30 / 100
2000 ms 9900 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llp;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#include "gap.h"

set<ll> S;

ll subtask1(int N) {
	//cerr << N << endl;
	ll l = 0, r = 1e18+1;
	ll q, w;
	while (N > 0) {
		MinMax(l, r, &q, &w);
		//cerr << q << w << endl;
		S.insert(q); S.insert(w);
		l = q+1;
		r = w-1;
		N -= 2;
	}
	set<ll>::iterator it = S.begin();
	it++;
	ll best = 0;
	for (; it != S.end(); it++) {
		set<ll>::iterator it2 = it;
		it2--;
		best = max(best, (*it) - (*it2));
	}
	return best;
}

void func(ll l, ll r) {
	if (l > r) return;
	if (l <= 0 || r <= 0) return;
	ll q, w;
	MinMax(l, r, &q, &w);
	if (q == -1) return;
	S.insert(q); S.insert(w);
	if (q == w) return;
	if (q == w-1) return;
	if (q == w-2) {
		func(q+1, q+1);
		return;
	}
	ll mid = (q+w)/2;
	if (q+1 != mid) func(q+1, mid);
	if (mid != w-1) func(mid, w-1);
}

ll subtask2(int N) {
	func(0, 1e18);
	set<ll>::iterator it = S.begin();

	/*set<ll>::iterator dbgit = it;
	while (dbgit != S.end()) {
		cerr << *dbgit << endl;
		dbgit++;
	}*/


	it++;
	ll best = 0;
	for (; it != S.end(); it++) {
		set<ll>::iterator it2 = it;
		it2--;
		best = max(best, (*it) - (*it2));
	}
	return best;
}

long long findGap(int T, int N)
{
	if (T == 1) return subtask1(N);
	else return subtask2(N);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5148 KB Output is correct
2 Correct 0 ms 5148 KB Output is correct
3 Correct 0 ms 5148 KB Output is correct
4 Correct 0 ms 5148 KB Output is correct
5 Correct 0 ms 5148 KB Output is correct
6 Correct 0 ms 5148 KB Output is correct
7 Correct 0 ms 5148 KB Output is correct
8 Correct 0 ms 5148 KB Output is correct
9 Correct 0 ms 5148 KB Output is correct
10 Correct 0 ms 5148 KB Output is correct
11 Correct 0 ms 5280 KB Output is correct
12 Correct 0 ms 5280 KB Output is correct
13 Correct 0 ms 5280 KB Output is correct
14 Correct 0 ms 5280 KB Output is correct
15 Correct 0 ms 5280 KB Output is correct
16 Correct 19 ms 6336 KB Output is correct
17 Correct 23 ms 6336 KB Output is correct
18 Correct 16 ms 6336 KB Output is correct
19 Correct 19 ms 6336 KB Output is correct
20 Correct 16 ms 6336 KB Output is correct
21 Correct 86 ms 9900 KB Output is correct
22 Correct 89 ms 9900 KB Output is correct
23 Correct 106 ms 9900 KB Output is correct
24 Correct 99 ms 9900 KB Output is correct
25 Correct 83 ms 9900 KB Output is correct
26 Correct 96 ms 9900 KB Output is correct
27 Correct 86 ms 9900 KB Output is correct
28 Correct 86 ms 9900 KB Output is correct
29 Correct 89 ms 9900 KB Output is correct
30 Correct 69 ms 9900 KB Output is correct
31 Correct 0 ms 5148 KB Output is correct
32 Correct 0 ms 5148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2000 ms 5148 KB Execution timed out
2 Execution timed out 2000 ms 5148 KB Execution timed out
3 Execution timed out 2000 ms 5148 KB Execution timed out
4 Execution timed out 2000 ms 5148 KB Execution timed out
5 Execution timed out 2000 ms 5148 KB Execution timed out
6 Execution timed out 2000 ms 5148 KB Execution timed out
7 Execution timed out 2000 ms 5148 KB Execution timed out
8 Execution timed out 2000 ms 5148 KB Execution timed out
9 Execution timed out 2000 ms 5148 KB Execution timed out
10 Execution timed out 2000 ms 5148 KB Execution timed out
11 Execution timed out 2000 ms 5148 KB Execution timed out
12 Execution timed out 2000 ms 5148 KB Execution timed out
13 Execution timed out 2000 ms 5148 KB Execution timed out
14 Execution timed out 2000 ms 5148 KB Execution timed out
15 Execution timed out 2000 ms 5148 KB Execution timed out
16 Execution timed out 2000 ms 5148 KB Execution timed out
17 Execution timed out 2000 ms 5148 KB Execution timed out
18 Execution timed out 2000 ms 5148 KB Execution timed out
19 Execution timed out 2000 ms 5148 KB Execution timed out
20 Execution timed out 2000 ms 5148 KB Execution timed out
21 Execution timed out 2000 ms 5148 KB Execution timed out
22 Execution timed out 2000 ms 5148 KB Execution timed out
23 Execution timed out 2000 ms 5148 KB Execution timed out
24 Execution timed out 2000 ms 5148 KB Execution timed out
25 Execution timed out 2000 ms 5148 KB Execution timed out
26 Execution timed out 2000 ms 5148 KB Execution timed out
27 Execution timed out 2000 ms 5148 KB Execution timed out
28 Execution timed out 2000 ms 5148 KB Execution timed out
29 Execution timed out 2000 ms 5148 KB Execution timed out
30 Execution timed out 2000 ms 5148 KB Execution timed out
31 Execution timed out 2000 ms 5148 KB Execution timed out
32 Execution timed out 2000 ms 5148 KB Execution timed out