이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gap.h"
#include <algorithm>
#include <cmath>
using namespace std;
long long findGap(int T, int N)
{
long long res = 0;
if(T == 1)
{
long long s, t;
long long mn;
long long mx;
s = 0;
t = 1000'000'000'000'000'000LL;
if(N % 2 == 0)
{
MinMax(s, t, &mn, &mx);
s = mn + 1;
t = mx - 1;
for(int i = 2; i <= N/2; i++)
{
MinMax(s, t, &mn, &mx);
res = max(res, mn - (s-1));
res = max(res, (t+1) - mx);
s = mn + 1;
t = mx - 1;
}
res = max(res, mx - mn);
}
else
{
MinMax(s, t, &mn, &mx);
s = mn + 1;
t = mx - 1;
for(int i = 2; i <= (N+1)/2; i++)
{
MinMax(s, t, &mn, &mx);
res = max(res, mn - (s-1));
res = max(res, (t+1) - mx);
s = mn + 1;
t = mx - 1;
}
}
}
else if(T == 2)
{
long long s, t;
long long mn, mx;
s = 0;
t = 1'000'000'000'000'000'000LL;
MinMax(s, t, &mn, &mx); //M += N+1
long long a1 = mn, aN = mx;
long long gap = (aN-a1)/(N-1) + ((aN-a1) % (N-1) != 0);
vector<long long> L, R;
L.push_back(a1);
R.push_back(a1);
for(long long x = a1+1; x < aN; x += gap)
{
MinMax(x, std::min(x+gap-1, aN-1), &mn, &mx);
if (mn != -1)
{
L.push_back(mn);
R.push_back(mx);
}
}
L.push_back(aN);
R.push_back(aN);
for(int i = 0; i < L.size()-1; i++)
{
res = max(res, L[i+1] - R[i]);
}
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 0; i < L.size()-1; i++)
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |