CSES - APIO 2016 - Results
Submission details
Task:Gap
Sender:Yytsi
Submission time:2019-04-14 15:11:47 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'll findGap(int, ll)':
input/code.cpp:17:7: error: 'MinMax' was not declared in this scope
       MinMax(l + 1, r - 1, &mn, &mx); // l < x, y < r
       ^~~~~~
input/code.cpp:17:7: note: suggested alternative: 'rindex'
       MinMax(l + 1, r - 1, &mn, &mx); // l < x, y < r
       ^~~~~~
       rindex
input/code.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       if (v.size() == N || mn == mx) break;
           ~~~~~~~~~^~~~
input/code.cpp:3:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i, a, b) for (int i=a; i<(b); i++)
                                     ^
input/code.cpp:27:5: note: in expansion of macro 'FOR'
     FOR(i,0,v.size()-1) res = max(res, v[i+1] - v[i]);
     ^~~
input/code.cpp:30:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

Code

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;

ll findGap(int T, ll N) {
  if (T == 1) {
    ll l = 0, r = 1e18 + 1;
    vector<ll> v;

    while (true) {
      ll mn, mx;
      MinMax(l + 1, r - 1, &mn, &mx); // l < x, y < r
      v.pb(mn);
      v.pb(mx);
      if (v.size() == N || mn == mx) break;
      l = mn, r = mx;
    }

    sort(v.begin(), v.end());

    ll res = 0;
    FOR(i,0,v.size()-1) res = max(res, v[i+1] - v[i]);
    return res;
  }
}