제출 #30913

#제출 시각아이디문제언어결과실행 시간메모리
30913sean617Gap (APIO16_gap)C++98
30 / 100
89 ms7552 KiB
#include "gap.h" #define SZ 100005 #include <iostream> #include <algorithm> #include <vector> typedef long long ll; using namespace std; ll a[SZ]; vector<ll> b; void f(ll p, ll q) { ll mn1, mx1, mn2, mx2; if (p > q) return; ll md = (p + q) / 2; MinMax(p, md, &mn1, &mx1); MinMax(md + 1, q, &mn2, &mx2); if (mn1 != -1) { b.push_back(mn1); if (mn1 != mx1) b.push_back(mx1); f(mn1 + 1, mx1 - 1); } if (mn2 != -1) { b.push_back(mn2); if (mn2 != mx2) b.push_back(mx2); f(mn2 + 1, mx2 - 1); } } long long findGap(int T, int N) { ll st = 0, en = 1e18, i = 0, j = N - 1, mn, mx, ans; if (T == 1) { while (i <= j) { MinMax(st, en, &mn, &mx); a[i] = mn; a[j] = mx; st = mn + 1; en = mx - 1; i++; j--; } ans = a[1] - a[0]; for (i = 1; i < N - 1; i++) { ans = max(ans, a[i + 1] - a[i]); } } else { f(st, en); sort(b.begin(), b.end()); ans = b[1] - b[0]; for (i = 1; i < N - 1; i++) { ans = max(ans, b[i + 1] - b[i]); } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...