Submission #104064

#TimeUsernameProblemLanguageResultExecution timeMemory
104064RockyBThe Big Prize (IOI17_prize)C++17
0 / 100
80 ms3680 KiB
/// 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; namespace com { static const int max_q = 10000; static int n; static int query_count = 0; static vector<int> g; static vector<vector<int> > rank_count; } namespace grader { using namespace com; vector<int> ask(int i) { query_count++; if(query_count > max_q) { cerr << "Query limit exceeded" << endl; exit(0); } if(i < 0 || i >= n) { cerr << "Bad index: " << i << endl; exit(0); } vector<int> res(2); res[0] = rank_count[g[i] - 1][i + 1]; res[1] = rank_count[g[i] - 1][n] - res[0]; return res; } } #ifdef IOI2018 using namespace grader; #endif map <int, vector <int > > dp; int _n; vector <int> get(int p) { if (dp.count(p)) return dp[p]; return dp[p] = ask(p); } /* if (a[l] < a[r]) -> x[0] != y[0] if (a[l] > a[r]) { x[0] == y[0] min(l, r) = a[r] x[0] > y[0] } */ /// [5 5 5 5 5 5 5 1 5] int mx; int solve(int l, int r, vector <int> x, vector <int> y) { if (!(max(x[0], x[1]))) return l; if (!(max(y[0], y[1]))) return r; if (r - l <= 1) return -1; if (x[0] == y[0]) return -1; if (x[0] + x[1] != mx || !x[0]) return solve(l + 1, r, get(l + 1), y); if (y[0] + y[1] != mx || !y[0]) return solve(l, r - 1, x, get(r - 1)); int m = l + r >> 1; if (rand() & 1) { int sol = solve(l, m, x, get(m)); if (~sol) return sol; return solve(m + 1, r, get(m + 1), y); } int on = solve(m + 1, r, get(m + 1), y); if (~on) return on; return solve(l, m, x, get(m)); } int find_best(int n) { rep(i, 0, min(500, n)) { vector <int> a = get(i); if (!max(a[0], a[1])) return i; mx = max(mx, a[0] + a[1]); } return solve(0, n - 1, get(0), get(n - 1)); } namespace read { using namespace com; void read() { cin >> n; g.resize(n); for(int i = 0; i < n; i++) { cin >> g[i]; if(g[i] < 1) { cerr << "Invalid rank " << g[i] << " at index " << i << endl; exit(0); } } int max_rank = *max_element(g.begin(), g.end()); rank_count.resize(max_rank + 1, vector<int>(n + 1, 0)); for(int r = 0; r <= max_rank; r++) { for(int i = 1; i <= n; i++) { rank_count[r][i] = rank_count[r][i - 1]; if(g[i - 1] == r) rank_count[r][i]++; } } for(int i = 0; i <= n; i++) for(int r = 1; r <= max_rank; r++) rank_count[r][i] += rank_count[r - 1][i]; int res = find_best(n); cout << res; ioi cout << res << endl << "Query count: " << query_count << endl; ioi } } #ifdef IOI2018 int main() { #ifdef IOI2018 freopen ("in.txt", "r", stdin); freopen ("slow.out", "w", stdout); #endif read :: read(); } #endif

Compilation message (stderr)

prize.cpp: In function 'int solve(int, int, std::vector<int>, std::vector<int>)':
prize.cpp:100:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = l + r >> 1;
          ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...