Submission #501364

#TimeUsernameProblemLanguageResultExecution timeMemory
501364kevinxiehkGap (APIO16_gap)C++17
Compilation error
0 ms0 KiB
#ifdef __cplusplus extern "C" { #endif void MinMax(long long s, long long t, long long* mn, long long* mx); long long findGap(int T, int N); #ifdef __cplusplus } #endif // TODO: global variables can be declared here long long max(long long a, long long b) { return (a > b ? a : b); } long long findGap(int T, int n) { // TODO: implementation if(T == 1) { long long arr[n + 5]; for(int i = 0; i < (n + 1) / 2; i++) { if(i == 0) MinMax(0, 1000000000000000000LL, &arr[0], &arr[n - 1]); else MinMax(arr[i - 1] + 1, arr[n - i] - 1, &arr[i], &arr[n - i - 1]); } long long ans = 0; for(int i = 0; i < n - 1; i++) ans = max(ans, arr[i + 1] - arr[i]); return ans; } else { long long l, r; MinMax(0, 1000000000000000000LL, &l, &r); long long chunk = (r - l + n - 2) / (n - 1); long long a, b, c = l; l++; long long ans = 0; while(l < r) { MinMax(l, l + chunk - 1, &a, &b); l += chunk; if(a == -1) continue; ans = max(ans, a - c); c = b; } ans = max(ans, r - c); return ans; } } #ifndef ONLINE_JUDGE #include <cstdio> #include <cmath> int subtask_num, N; long long A[100001]; long long call_count; void MinMax(long long s, long long t, long long* mn, long long* mx) { int lo = 1, hi = N, left = N+1, right = 0; if (s > t) { lo /= 0; } while (lo <= hi){ int mid = (lo+hi) >> 1; if (A[mid] >= s) hi = mid - 1, left = mid; else lo = mid + 1; } lo = 1, hi = N; while (lo <= hi) { int mid = (lo + hi) >> 1; if (A[mid] <= t) lo = mid + 1, right = mid; else hi = mid - 1; } if (left > right) *mn = *mx = -1; else{ *mn = A[left]; *mx = A[right]; } if (subtask_num == 1) call_count++; else if (subtask_num == 2) call_count += right - left + 2; } int main() { scanf("%d %d", &subtask_num, &N); for (int i = 1; i <= N; i++) { scanf("%lld", &A[i]); } printf("%lld\n", findGap(subtask_num, N)); printf("%lld\n", call_count); return 0; } #endif

Compilation message (stderr)

gap.cpp: In function 'void MinMax(long long int, long long int, long long int*, long long int*)':
gap.cpp:52:21: warning: division by zero [-Wdiv-by-zero]
   52 |     if (s > t) { lo /= 0; }
      |                  ~~~^~~~
gap.cpp: In function 'int main()':
gap.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     scanf("%d %d", &subtask_num, &N);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
gap.cpp:75:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |        scanf("%lld", &A[i]);
      |        ~~~~~^~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccp0daTe.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccDRvVIe.o:gap.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccp0daTe.o: in function `main':
grader.cpp:(.text.startup+0x1b7): undefined reference to `findGap(int, int)'
collect2: error: ld returned 1 exit status