Submission #40156

#TimeUsernameProblemLanguageResultExecution timeMemory
40156SpaimaCarpatilorGap (APIO16_gap)C++14
46.00 / 100
100 ms5928 KiB
#include "gap.h" #include<bits/stdc++.h> using namespace std; long long x[100009]; const long long xmax = 1e18; long long rand15 () {return rand () & 32767;} long long rand30 () {return (rand15 () << 15LL) | rand15 ();} long long rand60 () {return (rand30 () << 30LL) | rand30 ();} long long overallAns = 0; void U (long long val) { if (val > overallAns) overallAns = val; } void divide (long long bf, long long a, long long b, long long af) { if (a > b) return ; if (a == b) { long long x, y; MinMax (a, b, &x, &y); if (x == -1) { if (af != -1) U (af - bf); } else if (af != -1) U (af - x), U (x - bf); return ; } long long mid = a + rand60 () % (b - a); long long x, y, z, t; MinMax (a, mid, &x, &y); MinMax (mid + 1, b, &z, &t); if (x == -1) { if (bf != -1) { if (z != -1) U (z - bf); else U (af - bf); } } else { if (bf != -1) U (x - bf); if (x != y) divide (x, x + 1, y - 1, y); } if (z == -1) { if (y != -1) U (af - y); } else { if (x != -1) U (z - y); if (z != t) divide (z, z + 1, t - 1, t); if (af != -1) U (af - t); } } long long findGap(int T, int N) { srand (time (0)); if (T == 1) { long long a = 0, b = xmax; for (int i = 1, j = N; i<=j; i ++, j --) MinMax (a, b, &x[i], &x[j]), a = x[i] + 1, b = x[j] - 1; long long ans = x[2] - x[1]; for (int i=1; i<N; i++) if (x[i + 1] - x[i] > ans) ans = x[i + 1] - x[i]; return ans; } divide (-1, 0, xmax, -1); return overallAns; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...