제출 #808730

#제출 시각아이디문제언어결과실행 시간메모리
808730someone코알라 (APIO17_koala)C++14
63 / 100
10 ms384 KiB
#include "koala.h" #include <bits/stdc++.h> using namespace std; const int MAX = 1e2 + 42, INF = 1e3 + 42; int n, w, perm[MAX]; int minValue(int N, int W) { // TODO: Implement Subtask 1 solution here. // You may leave this function unmodified if you are not attempting this // subtask. return 0; } int maxValue(int N, int W) { // TODO: Implement Subtask 2 solution here. // You may leave this function unmodified if you are not attempting this // subtask. return 0; } int greaterValue(int N, int W) { // TODO: Implement Subtask 3 solution here. // You may leave this function unmodified if you are not attempting this // subtask. return 0; } int simulate(int cost, deque<int> other, deque<int> act) { int stone = w, sum = 0, nb = 0; while((stone % cost) != 0 && other[0] != 0) { stone--; other.pop_front(); } for(int i = 0; i < cost && other[i]; i++) sum += other[i]; while(stone >= cost && (act[0] != 0 || other[0] != 0)) { if(sum < act[0]) { nb++; stone -= cost; act.pop_front(); } else { sum = 0; for(int i = 0; i < cost && other[0]; i++) { stone--; other.pop_front(); } for(int i = 0; i < cost && other[i]; i++) sum += other[i]; } } return nb; } void DPR(int left, int right, vector<int> pos) { if(pos.empty()) return; if(left == right) { perm[pos[0]] = left; return; } deque<int> other, act; act.push_back(0); other.push_back(0); for(int i = 1; i <= n; i++) { if(i < left || i > right) other.push_front(i); else act.push_front(i); } int sz = (int)pos.size(), nb = 0, best = INF; for(int i = 1; i * sz <= w; i++) { int chosen = simulate(i+1, other, act); if(abs(sz - 2 * chosen) < best) { nb = i; best = abs(sz - 2 * chosen); } if(chosen == 0) i = w + 1; } int B[n], R[n]; for(int i = 0; i < n; i++) B[i] = R[i] = 0; for(int p : pos) B[p] = nb; playRound(B, R); vector<int> posInf, posSup; for(int p : pos) if(R[p] >= nb+1) posSup.push_back(p); else posInf.push_back(p); DPR(left, left - 1 + (int)posInf.size(), posInf); DPR(left + (int)posInf.size(), right, posSup); } void allValues(int N, int W, int *P) { n = N, w = W; vector<int> vals, pos; for(int i = 0; i < n; i++) pos.push_back(i); for(int i = 0; i < n; i++) vals.push_back(i+1); DPR(1, N, pos); for(int i = 0; i < n; i++) P[i] = perm[i]; }
#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...