This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "prize.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define ft first
#define sd second
#define pi pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(...) dbg_out(__VA_ARGS__)
using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;
//Constants
const ll INF = 5 * 1e18;
const int IINF = 2 * 1e9;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ld PI = 3.14159265359;
//Templates
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';}
void dbg_out() {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }
template<typename T> void mins(T& x, T y) {x = min(x, y);}
template<typename T> void maxs(T& x, T y) {x = max(x, y);}
template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
int find_best(int n) {
vector<vector<int>> mem(n + 5, {-1, -1});
auto myask = [&](int i) {
if (mem[i][0] == -1) {
return mem[i] = ask(i);
} else {
return mem[i];
}
};
int mx = 0, mx_i;
for (int i = 0; i < min(n, 480); i++) {
vector<int> res = myask(i);
int cur = res[0] + res[1];
maxs(mx, cur);
if (cur == mx) {
mx_i = i;
}
if (cur == 0) return i;
}
int i = mx_i;
while (i < n) {
vector<int> cur = myask(i);
int lo = i, hi = n - 1;
int to = n;
while (lo <= hi) {
int mi = (lo + hi) / 2;
vector<int> res = myask(mi);
if (res[0] + res[1] == 0) return mi;
if (res[0] + res[1] < mx) {
to = mi;
hi = mi - 1;
} else {
if (res[0] == cur[0]) {
lo = mi + 1;
} else {
hi = mi - 1;
}
}
}
while (to < n) {
vector<int> res = myask(to);
if (res[0] + res[1] == 0) return to;
if (res[0] + res[1] == mx) break;
to++;
}
i = to;
}
return 0;
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:59:28: warning: 'mx_i' may be used uninitialized in this function [-Wmaybe-uninitialized]
59 | vector<int> cur = myask(i);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |