답안 #1012075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012075 2024-07-01T15:27:50 Z zsombor Gap (APIO16_gap) C++17
100 / 100
42 ms 2684 KB
#include "gap.h"
#include <vector>
using namespace std;
using ll = long long;

const ll m = 1000000000000000000;

ll solve1(ll n) {
	ll l = 0, r = m, mn, mx, ans = 0;
	vector <ll> v;
	vector <ll> v2;
	while (v.size() + v2.size() < n) {
		MinMax(l, r, &mn, &mx);
		l = mn + 1;
		r = mx - 1;
		v.push_back(mn);
		v2.push_back(mx);
	}
	while (v2.size()) { v.push_back(v2.back()); v2.pop_back(); }
	for (int i = 1; i < v.size(); i++) ans = max(ans, v[i] - v[i - 1]);
	return ans;
}

ll solve2(ll n) {
	ll a1, an, mn, mx, ans = 0;
	MinMax(0, m, &a1, &an);
	ll u = a1, d = a1, l = (an - a1) / (n - 1);
	if (l * (n - 1) < an - a1) l++;
	while (d < an) {
		MinMax(d + 1, d + l, &mn, &mx);
		d += l;
		if (mn == -1) continue;
		ans = max(ans, mn - u);
		u = mx;
	}
	return ans;
}

ll findGap(int T, int N) {
	return (T == 1 ? solve1(N) : solve2(N));
}

Compilation message

gap.cpp: In function 'll solve1(ll)':
gap.cpp:12:30: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   12 |  while (v.size() + v2.size() < n) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~
gap.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for (int i = 1; i < v.size(); i++) ans = max(ans, v[i] - v[i - 1]);
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 356 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 6 ms 928 KB Output is correct
17 Correct 6 ms 972 KB Output is correct
18 Correct 6 ms 1112 KB Output is correct
19 Correct 6 ms 1112 KB Output is correct
20 Correct 6 ms 1112 KB Output is correct
21 Correct 27 ms 2588 KB Output is correct
22 Correct 25 ms 2560 KB Output is correct
23 Correct 31 ms 2660 KB Output is correct
24 Correct 30 ms 2576 KB Output is correct
25 Correct 32 ms 2672 KB Output is correct
26 Correct 39 ms 2588 KB Output is correct
27 Correct 24 ms 2684 KB Output is correct
28 Correct 39 ms 2684 KB Output is correct
29 Correct 39 ms 2676 KB Output is correct
30 Correct 21 ms 2684 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 8 ms 600 KB Output is correct
17 Correct 8 ms 420 KB Output is correct
18 Correct 8 ms 600 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 39 ms 1180 KB Output is correct
22 Correct 42 ms 1112 KB Output is correct
23 Correct 32 ms 1112 KB Output is correct
24 Correct 35 ms 1112 KB Output is correct
25 Correct 30 ms 1112 KB Output is correct
26 Correct 31 ms 1112 KB Output is correct
27 Correct 32 ms 1112 KB Output is correct
28 Correct 35 ms 1368 KB Output is correct
29 Correct 30 ms 1112 KB Output is correct
30 Correct 18 ms 1112 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct