This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// In The Name Of God
#include <bits/stdc++.h>
#ifndef IOI2018
#include "prize.h"
#endif
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl '\n'
#define ioi exit(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
map <int, vector <int > > dp;
int n;
vector <int> get(int p) {
p = n - p - 1;
if (dp.count(p)) return dp[p];
return dp[p] = ask(p);
}
int solve(int p, int n) {
while (p < n) {
int l = p + 1, r = n - 1, res = p;
vector <int> cur = get(p);
while (l <= r) {
int mid = l + r >> 1;
vector <int> now = get(mid);
if ((now[0] + now[1] == cur[0] + cur[1]) && now[0] == cur[0]) {
res = mid, l = mid + 1;
}
else r = mid - 1;
}
++res;
while (res < n) {
vector <int> now = get(res);
if (!max(now[0], now[1])) return res;
if (now[0] + now[1] == cur[0] + cur[1]) break;
++res;
}
p = res;
}
assert(0);
}
int find_best(int _n) {
int mx = -1, p = -1;
n = _n;
rep(i, 0, min(473, n)) {
#ifndef IOI2018
vector <int> a = get(i);
#endif
#ifdef IOI2018
vector <int> a = grader :: get(i);
#endif
if (a[0] + a[1] == 0) return i;
if (a[0] + a[1] > mx) {
mx = a[0] + a[1];
p = i;
}
}
return solve(p, n);
}
#ifdef IOI2018
int main() {
#ifdef IOI2018
freopen ("in.txt", "r", stdin);
freopen ("D.out", "w", stdout);
#endif
read :: read();
}
#endif
Compilation message (stderr)
prize.cpp: In function 'int solve(int, int)':
prize.cpp:57:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |