Submission #1165436

#TimeUsernameProblemLanguageResultExecution timeMemory
1165436steveonalexKoala Game (APIO17_koala)C++20
85 / 100
53 ms464 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1ULL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(a, b);} ll lcm(ll a, ll b){return a / gcd(a, b) * b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ull mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} //mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); mt19937_64 rng(1); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } #include "koala.h" int minValue(int n, int w) { int a[n], b[n]; memset(a, 0, sizeof a); memset(b, 0, sizeof b); a[0] = 1; playRound(a, b); if (b[0] < a[0]){ return 0; } else{ for(int i = 1; i < n; ++i) if (b[i] <= a[i]) return i; } assert(false); return 0; } int maxValue(int n, int w) { vector<int> S; for(int i = 0; i < n; ++i) S.push_back(i); int tot = 100; while(S.size() > 1){ int a[n], b[n]; memset(a, 0, sizeof a); memset(b, 0, sizeof b); int dih = tot / S.size(); for(int i: S) a[i] = dih; playRound(a, b); vector<int> T; for(int i: S) if (b[i] > a[i]) T.push_back(i); S = T; } if (S.size() == 0) assert(false); return S[0]; } bool cmp1(int x, int y){ const int n = 100; if (x == y) return false; vector<int> blocked_cells; while(true){ int a[n], b[n]; memset(a, 0, sizeof a); memset(b, 0, sizeof b); a[x] = a[y] = blocked_cells.size() + 1; if (a[x] == 7) a[x] = a[y] = 8; int dih = 100 - 2 * (blocked_cells.size() + 1); for(int i: blocked_cells) a[i] = dih / blocked_cells.size(); playRound(a, b); bool b1 = b[x] > a[x], b2 = b[y] > a[y]; if (b1 && b2){ for(int i = 0; i < n; ++i) if (i != x && i != y && b[i] <= a[i]) blocked_cells.push_back(i); remove_dup(blocked_cells); } else if (b1) return false; else return true; } } bool cmp2(int x, int y){ const int n = 100; if (x == y) return false; int a[n], b[n]; memset(a, 0, sizeof a); memset(b, 0, sizeof b); a[x] = a[y] = 100; playRound(a, b); if (b[x] > a[x]) return false; return true; } int greaterValue(int n, int w) { if (cmp1(0, 1)) return 1; return 0; } void optimal_sort(vector<int> &a, function<bool(int, int)> cmp){ vector<int> ans; for(int i: a){ int l = 0, r = ans.size(); while(l < r){ int mid = (l + r) >> 1; if (cmp(i, ans[mid])) r = mid; else l = mid + 1; } ans.insert(ans.begin() + l, i); } a = ans; } void allValues(int n, int w, int *P) { if (w == 2*n) { vector<int> perm(n); for(int i = 0; i < n; ++i) perm[i] = i; optimal_sort(perm, cmp2); for(int i = 0; i < n; ++i) P[perm[i]] = i + 1; } else { for(int i = 0; i < n; ++i) P[i] = 0; vector<vector<int>> suffix(n+1); for(int i = 0; i < n; ++i) suffix[1].push_back(i); for(int it = 100; it >= 1; ){ vector<int> S; for(int i = it; i >= 1; --i) if (suffix[i].size()){ for(int j: suffix[i]) if (P[j] == 0) S.push_back(j); break; } int tot = it; while(S.size() > 5){ suffix[it - S.size() + 1] = S; int a[n], b[n]; memset(a, 0, sizeof a); memset(b, 0, sizeof b); int dih = tot / S.size(); for(int i: S) { a[i] = dih; } playRound(a, b); vector<int> T; for(int i: S) if (b[i] > a[i]) T.push_back(i); S = T; } if (S.size() == 0) assert(false); optimal_sort(S, cmp1); reverse(ALL(S)); for(int i = 0; i < (int) S.size(); ++i) P[S[i]] = it - i; it -= S.size(); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...