답안 #992090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992090 2024-06-03T21:23:07 Z MladenP Gap (APIO16_gap) C++17
100 / 100
43 ms 3060 KB
#include "gap.h"
#include <algorithm>
#include <iostream> 

using namespace std;

const long long MIN = 0;
const long long MAX = 1'000'000'000'000'000'000;
long long findGap(int T, int N)
{
	if (T == 1) {
		long long mn, mx; 
		long long prev_mn, prev_mx;
		long long sol = 0;
		MinMax(MIN, MAX, &prev_mn, &prev_mx);
		for (int i = 3; i <= N; i+=2) {
			MinMax(prev_mn+1, prev_mx-1, &mn, &mx);
			sol = max(sol, prev_mx-mx);
			sol = max(sol, mn-prev_mn);
			prev_mn = mn;
			prev_mx = mx;
		}
		if (prev_mn != prev_mx) {
			sol = max(sol, prev_mx-prev_mn);
		}
		return sol;
	} else if (T == 2) {
		long long mn, mx;
		MinMax(MIN, MAX, &mn, &mx); // N+1
		long long diff = (mx-mn + N-2)/(N-1), sol = 0, prev_mx = mn, st = mn+1;
		while (st <= mx) {
			long long en = min(mx, st+diff), cur_mn, cur_mx;
			MinMax(st, en, &cur_mn, &cur_mx);
			if (cur_mn != -1) {
				sol = max(sol, cur_mn - prev_mx);
				prev_mx = cur_mx;
			}
			st = en+1;
		}
		return sol;
	}
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 7 ms 2392 KB Output is correct
17 Correct 7 ms 2392 KB Output is correct
18 Correct 6 ms 2392 KB Output is correct
19 Correct 8 ms 2392 KB Output is correct
20 Correct 6 ms 2392 KB Output is correct
21 Correct 25 ms 2648 KB Output is correct
22 Correct 26 ms 2648 KB Output is correct
23 Correct 25 ms 2676 KB Output is correct
24 Correct 25 ms 2648 KB Output is correct
25 Correct 23 ms 2648 KB Output is correct
26 Correct 26 ms 2648 KB Output is correct
27 Correct 34 ms 2836 KB Output is correct
28 Correct 25 ms 2648 KB Output is correct
29 Correct 25 ms 2648 KB Output is correct
30 Correct 21 ms 2648 KB Output is correct
31 Correct 0 ms 2392 KB Output is correct
32 Correct 0 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 2 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 10 ms 2392 KB Output is correct
17 Correct 9 ms 2508 KB Output is correct
18 Correct 11 ms 2644 KB Output is correct
19 Correct 11 ms 2592 KB Output is correct
20 Correct 5 ms 2392 KB Output is correct
21 Correct 35 ms 2840 KB Output is correct
22 Correct 36 ms 2744 KB Output is correct
23 Correct 38 ms 3060 KB Output is correct
24 Correct 34 ms 2648 KB Output is correct
25 Correct 34 ms 2648 KB Output is correct
26 Correct 38 ms 2648 KB Output is correct
27 Correct 34 ms 2648 KB Output is correct
28 Correct 35 ms 2648 KB Output is correct
29 Correct 43 ms 2648 KB Output is correct
30 Correct 26 ms 2648 KB Output is correct
31 Correct 0 ms 2392 KB Output is correct
32 Correct 0 ms 2392 KB Output is correct