제출 #47670

#제출 시각아이디문제언어결과실행 시간메모리
47670E869120Gap (APIO16_gap)C++14
100 / 100
91 ms4456 KiB
#include "gap.h"
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

long long a[100009]; int res = 0, maxn = 0;
vector<long long>Q;

long long findGap(int T, int N)
{
	if (T == 1 || N <= 8) {
		long long L = 0, R = 1000000000000000000LL, s, t, cnt = 0;

		while (cnt < (N + 1) / 2) {
			MinMax(L, R, &s, &t);
			L = s; R = t;
			if (L != -1) { a[cnt + 1] = L; a[N - cnt] = R; }
			cnt++; L++; R--;
		}
		long long maxn = 0;
		for (int i = 1; i <= N - 1; i++) maxn = max(maxn, a[i + 1] - a[i]);
		return maxn;
	}
	if (T == 2) {
		long long s, t; MinMax(0, 1000000000000000000LL, &s, &t); t++;
		
		long long T = N - 1;
		vector<long long>B; long double L = 1.0L*(t - s) / T;
		for (int i = 0; i <= T; i++) B.push_back(s + (long long)(1.0L*L*i));
		B[T] = t;

		for (int i = 0; i < B.size() - 1; i++) {
			MinMax(B[i], B[i + 1] - 1, &s, &t);
			//cout << B[i] << " " << B[i + 1] - 1 << " " << s << " " << t << endl;
			if (s != -1) {
				Q.push_back(s);
				Q.push_back(t);
			}
		}
		sort(Q.begin(), Q.end());
		Q.erase(unique(Q.begin(), Q.end()), Q.end());

		long long maxn = 0;
		for (int i = 0; i < Q.size() - 1; i++) maxn = max(maxn, Q[i + 1] - Q[i]);
		return maxn;
	}
	return 0;
}

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

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:33:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < B.size() - 1; i++) {
                   ~~^~~~~~~~~~~~~~
gap.cpp:45:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < Q.size() - 1; i++) maxn = max(maxn, Q[i + 1] - Q[i]);
                   ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...