이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gap.h"
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
LL Solve1(int N) {
vector<LL> V(N, 0);
LL a = 0, b = 1000000000000000000LL;
a--, b++;
for (int i = 0, j = N - 1; i <= j; i++, j--) {
LL c, d;
MinMax(a, b, &c, &d);
V[i] = c;
V[j] = d;
a = c + 1;
b = d - 1;
}
LL ans = 0;
for (int i = 0; i < N - 1; i++) ans = max(ans, V[i + 1] - V[i]);
return ans;
}
LL Solve2(int N) {
vector<LL> V;
LL a = 0, b = 1000000000000000000LL;
a--, b++;
{
LL c, d;
MinMax(a, b, &c, &d);
a = c, b = d;
}
if (N <= 2) return b - a;
LL gap = (b - a + N - 2)/(N - 1);
V.push_back(a);
V.push_back(b);
for (LL i = a; i <= b; i += gap + 1) {
LL c, d;
MinMax(i, i + gap, &c, &d);
V.push_back(c);
V.push_back(d);
}
sort(V.begin(), V.end());
LL ans = 0;
for (int i = 1; i < V.size(); i++) ans = max(ans, V[i] - V[i - 1]);
return ans;
}
long long findGap(int T, int N)
{
if (T == 1) return Solve1(N);
else return Solve2(N);
}
컴파일 시 표준 에러 (stderr) 메시지
gap.cpp: In function 'LL Solve2(int)':
gap.cpp:46:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < V.size(); i++) ans = max(ans, V[i] - V[i - 1]);
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |