제출 #107819

#제출 시각아이디문제언어결과실행 시간메모리
107819Noam527Gap (APIO16_gap)C++17
100 / 100
106 ms3344 KiB
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 1;
const int OOO = 1;
using namespace std;

void MinMax(ll s, ll t, ll *mn, ll *mx);

ll findGap(int t, int n) {
	ll lo, hi, a, b;
	MinMax(0, inf, &lo, &hi);
	if (t == 2) {
		vector<ll> pos;
		ll d = (hi - lo) / (n - 1);
		pos.push_back(lo);
		for (ll i = lo + 1; i < hi; i += d + 1) {
			MinMax(i, min(hi - 1, i + d), &a, &b);
			if (a != -1) {
				pos.push_back(a);
				pos.push_back(b);
			}
		}
		pos.push_back(hi);
		ll rtn = pos[1] - pos[0];
		for (int i = 2; i < pos.size(); i++)
			rtn = max(rtn, pos[i] - pos[i - 1]);
		return rtn;
	}
	vector<ll> pos = { lo, hi };
	int left = n - 2;
	while (left > 0) {
		MinMax(lo + 1, hi - 1, &lo, &hi);
		pos.push_back(lo);
		pos.push_back(hi);
		left -= 2;
	}
	sort(pos.begin(), pos.end());
	ll rtn = pos[1] - pos[0];
	for (int i = 2; i < pos.size(); i++)
		rtn = max(rtn, pos[i] - pos[i - 1]);
	return rtn;
}
/*
int main() {
	ll ans = findGap(0, 4);
	cout << "my ans " << ans << '\n';
}
*/

컴파일 시 표준 에러 (stderr) 메시지

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:30:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 2; i < pos.size(); i++)
                   ~~^~~~~~~~~~~~
gap.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 2; i < pos.size(); i++)
                  ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...