답안 #388578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388578 2021-04-12T07:20:24 Z talant117408 Gap (APIO16_gap) C++17
100 / 100
69 ms 2364 KB
#include "gap.h"
#include <bits/stdc++.h>
 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll findGap(int T, int n) {
	if (T == 1) {
		vector <ll> v;
		ll l = 1, r = 1e18;
		ll mn = 0, mx = 0;
		while (l <= r) {
			if (sz(v) == n) break;
			MinMax(l, r, &mn, &mx);
			if (mn == -1 && mx == -1) {
				break;
			}
			v.pb(mn);
			if (mn != mx) v.pb(mx);
			l = mn+1; r = mx-1;
		}
		sort(all(v));
		ll ans = 0;
		for (int i = 0; i < n-1; i++) ans = max(ans, v[i+1]-v[i]);
		return ans;
	}
	else {
		vector <ll> v;
		ll mn, mx;
		MinMax(0, 1e18, &mn, &mx);
		ll k = (mx-mn+n-1)/n;
		v.pb(mn); v.pb(mx);
		ll MN = mn, MX = mx;
		for (ll i = MN+1; i <= MX-1; i += k) {
			MinMax(i, min(MX-1, i+k-1), &mn, &mx);
			if (mn != -1 && mx != -1) {
				if (mn == mx) {
					v.pb(mn);
				}
				else {
					v.pb(mn); v.pb(mx);
				}
			}
		}
		sort(all(v));
		ll ans = 0;
		for (int i = 0; i < sz(v)-1; i++) ans = max(ans, v[i+1]-v[i]);
		return ans;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 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 12 ms 840 KB Output is correct
17 Correct 12 ms 840 KB Output is correct
18 Correct 12 ms 828 KB Output is correct
19 Correct 12 ms 840 KB Output is correct
20 Correct 10 ms 840 KB Output is correct
21 Correct 48 ms 2364 KB Output is correct
22 Correct 48 ms 2192 KB Output is correct
23 Correct 51 ms 2228 KB Output is correct
24 Correct 54 ms 2232 KB Output is correct
25 Correct 43 ms 2232 KB Output is correct
26 Correct 48 ms 2232 KB Output is correct
27 Correct 48 ms 2196 KB Output is correct
28 Correct 49 ms 2232 KB Output is correct
29 Correct 52 ms 2132 KB Output is correct
30 Correct 43 ms 2300 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 0 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 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 908 KB Output is correct
18 Correct 15 ms 840 KB Output is correct
19 Correct 15 ms 880 KB Output is correct
20 Correct 7 ms 456 KB Output is correct
21 Correct 63 ms 2140 KB Output is correct
22 Correct 62 ms 2252 KB Output is correct
23 Correct 61 ms 2236 KB Output is correct
24 Correct 67 ms 2232 KB Output is correct
25 Correct 56 ms 2224 KB Output is correct
26 Correct 63 ms 2196 KB Output is correct
27 Correct 63 ms 2148 KB Output is correct
28 Correct 69 ms 2232 KB Output is correct
29 Correct 63 ms 2204 KB Output is correct
30 Correct 34 ms 1548 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 1 ms 328 KB Output is correct