제출 #590766

#제출 시각아이디문제언어결과실행 시간메모리
590766Namnamseo코알라 (APIO17_koala)C++17
47 / 100
49 ms432 KiB
#include "koala.h" #include <algorithm> #include <cstdio> #include <functional> #include <vector> #include <numeric> using namespace std; using vi=vector<int>; #define all(v) v.begin(), v.end() vi Play(vi q) { vi ret(q.size()); playRound(q.data(), ret.data()); return ret; } int minValue(int N, int W) { vi v(N); v[0] = 1; vi res = Play(v); if (res[0] >= 1) res[0] -= 1; for (int i=0; i<N; ++i) if (!res[i]) return i; return 0; } int maxValue(int N, int W) { vi larger(N); iota(larger.begin(), larger.end(), 0); while (larger.size() > 1u) { vi mask(N); int afford = W / larger.size(); for (int i:larger) mask[i] = afford; auto res = Play(mask); vi larger_new; for (int i:larger) if (res[i]) larger_new.push_back(i); larger = larger_new; } return larger[0]; } int greaterValue(int N, int W) { int l = 0, r = 15; vi q(N); for (;;) { int m = (l+r)/2; q[0] = q[1] = m; vi res = Play(q); if (res[0] != res[1]) { return res[0] < res[1]; } if (!res[0]) r = m; else l = m; } return 0; } void sort_merge(vector<int> &v, int l, int r, function<bool(const int&, const int&)> comp) { if (l >= r) return; int md = (l+r)/2; sort_merge(v, l, md, comp); sort_merge(v, md+1, r, comp); static int tmp[110]; int oi=0, il=l, ir=md+1; while (il<=md || ir<=r) { if (il<=md && (ir>r || comp(v[il], v[ir]))) tmp[oi++] = v[il++]; else tmp[oi++] = v[ir++]; } for (int i=0; i<oi; ++i) v[l+i] = tmp[i]; } void allValues(int N, int W, int *P) { if (W == 2*N) { vi buf(N); fill(all(buf), 2); vi tmp = Play(buf); vi large, small; for (int i=0; i<N; ++i) { if (tmp[i] > 2) { large.push_back(i); } else { small.push_back(i); } } vi ss, sl, ls, ll; fill(all(buf), 0); for (int x : large) buf[x] = 3; tmp = Play(buf); for (int x : large) { if (tmp[x] > 3) ll.push_back(x); else ls.push_back(x); } for (int x : small) { if (tmp[x] > 0) sl.push_back(x); else ss.push_back(x); } fill(all(buf), 0); auto Sort = [&](vi &v) { sort_merge(v, 0, int(v.size())-1, [&](const int& a, const int& b) { buf[a] = buf[b] = 100; tmp = Play(buf); buf[a] = buf[b] = 0; return tmp[a] < tmp[b]; }); }; Sort(ss); Sort(sl); Sort(ls); Sort(ll); vi out; out.insert(out.end(), all(ss)); out.insert(out.end(), all(sl)); out.insert(out.end(), all(ls)); out.insert(out.end(), all(ll)); for (int i=0; i<N; ++i) P[out[i]] = 1+i; } else { // TODO: Implement Subtask 5 solution here. // You may leave this block unmodified if you are not attempting this // subtask. } }
#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...