| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1018943 | coolboy19521 | Gap (APIO16_gap) | C++17 | 54 ms | 2396 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include "gap.h"
using namespace std;
const int sz = 1e5 + 5;
long long a[sz];
long long findGap(int T, int N) {
if (1 == T) {
long long mn, mx;
MinMax(0, 1e18, &mn, &mx);
a[1] = mn;
a[N] = mx;
for (int i = 1; i <= (N+1)/2-1; i ++) {
MinMax(mn+1, mx-1, &mn, &mx);
a[i+1] = mn;
a[N - i] = mx;
}
long long gp = 0;
for (int i = 1; i <= N-1; i ++)
gp = max(gp, a[i+1] - a[i]);
return gp;
}
if (T == 2) {
long long mn, mx;
MinMax(0, 1e18, &mn, &mx);
vector<long long> b = {mn, mx};
long long k = (mx - mn) / (N - 1);
while (b.size() < N) {
long long nextMin, nextMax;
long long rangeStart = mn + 1;
long long rangeEnd = min(mx - 1, mn + k);
if (rangeStart > rangeEnd) break;
MinMax(rangeStart, rangeEnd, &nextMin, &nextMax);
if (nextMin == -1) { // No numbers found in the range
mn = rangeEnd + 1;
continue;
}
int tmNM = nextMax;
b.push_back(nextMin);
if (nextMin != nextMax) {
b.push_back(nextMax);
while (nextMin < nextMax && b.size() < N) {
// Keep querying within the narrowed range
MinMax(nextMin + 1, nextMax - 1, &nextMin, &nextMax);
if (nextMin == -1) break; // Exit if no more numbers are found
if (nextMin == nextMax) {
b.push_back(nextMin);
break;
} else {
b.push_back(nextMin);
b.push_back(nextMax);
}
}
}
mn = tmNM + 1; // Move to the next range beyond the last found max
}
// Sorting the elements to find the maximum gap
sort(begin(b), end(b));
long long maxGap = 0;
for (int i = 0; i < b.size() - 1; i++) {
maxGap = max(maxGap, b[i + 1] - b[i]);
}
return maxGap;
}
return 0; // This part should never be reached for T = 2
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
