답안 #328161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
328161 2020-11-15T13:39:54 Z couplefire Gap (APIO16_gap) C++17
100 / 100
67 ms 3216 KB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;

long long solve1(int n){
	queue<long long> left; stack<long long> right;
	long long cl = 0, cr = 1000000000000000000;
	while(left.size()+right.size() < n){
		long long a, b;
		MinMax(cl, cr, &a, &b);
		left.push(a); right.push(b);
		cr = b-1, cl = a+1;
	}
	vector<long long> v;
	while(!left.empty()){
		v.push_back(left.front());
		left.pop();
	}
	while(!right.empty()){
		v.push_back(right.top());
		right.pop();
	}
	long long ans = 0;
	for(int i = 1; i<v.size(); i++) ans = max(ans, v[i]-v[i-1]);
	return ans;
}

long long solve2(int n){
	long long left, right;
	MinMax(0, 1000000000000000000, &left, &right);
	long long gap = (right-left+n-2)/(n-1);
	if(right - left == 1ll*(n-1)) return 1;
	gap--;
	long long prev = left;
	long long cur = left+1;
	long long ans = 0;
	while(cur<right){
		long long cl, cr;
		MinMax(cur, cur+gap, &cl, &cr);
		if(cl == -1){
			cur += gap+1;
			continue;
		}
		ans = max(ans, cl-prev);
		ans = max(ans, cr-cl);
		prev = cr;
		cur += gap+1;
	}
	return ans;
}

long long findGap(int T, int N){
	if(T == 1) return solve1(N);
	return solve2(N);
}

Compilation message

gap.cpp: In function 'long long int solve1(int)':
gap.cpp:8:33: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    8 |  while(left.size()+right.size() < n){
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
gap.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i = 1; i<v.size(); i++) ans = max(ans, v[i]-v[i-1]);
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 12 ms 1132 KB Output is correct
17 Correct 11 ms 1132 KB Output is correct
18 Correct 12 ms 1132 KB Output is correct
19 Correct 11 ms 1132 KB Output is correct
20 Correct 9 ms 1132 KB Output is correct
21 Correct 44 ms 3044 KB Output is correct
22 Correct 44 ms 3044 KB Output is correct
23 Correct 46 ms 3216 KB Output is correct
24 Correct 51 ms 3044 KB Output is correct
25 Correct 40 ms 3044 KB Output is correct
26 Correct 45 ms 3056 KB Output is correct
27 Correct 47 ms 3152 KB Output is correct
28 Correct 44 ms 3044 KB Output is correct
29 Correct 46 ms 3200 KB Output is correct
30 Correct 36 ms 3044 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 14 ms 492 KB Output is correct
17 Correct 16 ms 492 KB Output is correct
18 Correct 15 ms 492 KB Output is correct
19 Correct 14 ms 492 KB Output is correct
20 Correct 7 ms 492 KB Output is correct
21 Correct 59 ms 1132 KB Output is correct
22 Correct 60 ms 1132 KB Output is correct
23 Correct 65 ms 1152 KB Output is correct
24 Correct 59 ms 1132 KB Output is correct
25 Correct 54 ms 1120 KB Output is correct
26 Correct 60 ms 1132 KB Output is correct
27 Correct 60 ms 1060 KB Output is correct
28 Correct 67 ms 1132 KB Output is correct
29 Correct 59 ms 1260 KB Output is correct
30 Correct 32 ms 1132 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct