제출 #720360

#제출 시각아이디문제언어결과실행 시간메모리
720360joelgun14Gap (APIO16_gap)C++17
30 / 100
45 ms3208 KiB
#include "gap.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;

long long findGap(int T, int N)
{
	// can call findmax function
	// let's say range is between 1 to 1e18
	// divide n into blocks size n / k
	if(T == 1) {
		ll l = 0, r = 1e18;
		ll a[N];
		for(int i = 0; i < N / 2 + N % 2; ++i) {
			MinMax(l, r, &a[i], &a[N - i - 1]);
			l = a[i] + 1, r = a[N - i - 1] - 1;
		}
		ll mxdiff = 0;
		for(int i = 1; i < N; ++i)
			mxdiff = max(mxdiff, a[i] - a[i - 1]);
		return mxdiff;
	}
	else {
		// divide N blocks size len / N into blocks
		ll l, r;
		MinMax((ll)0, (ll)1e18, &l, &r);
		if(N == 2)
			return r - l;
		ll minres = (r - l + N - 2) / (N - 1);
		// kita query dr l + 1 ke l + min_res
		// n - 1 query total n elem?
		vector<ll> x = {l};
		for(int i = 0; i < N; ++i) {
			ll a, b;
			MinMax(l + minres * i + 1, l * minres * (i + 1), &a, &b);
			if(a != -1)
				x.push_back(a), x.push_back(b);
		}
		ll res = 0;
		for(int i = 1; i < x.size(); ++i)
			res = max(res, x[i] - x[i - 1]);
		return res;
	}
	return 0;
}

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

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(int i = 1; i < x.size(); ++i)
      |                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...