# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
609884 | KoD | 버섯 세기 (IOI20_mushrooms) | C++17 | 10 ms | 464 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "mushrooms.h"
#include <bits/stdc++.h>
using std::array;
using std::pair;
using std::tuple;
using std::vector;
constexpr int K = 80;
int count_mushrooms(int n) {
vector<char> color(n);
array<vector<int>, 2> list = {};
list[0].push_back(0);
int k = 1;
while (k < n and (int)std::max(list[0].size(), list[1].size()) < K) {
if (k + 1 == n or (list[0].size() <= 1 and list[1].size() <= 1)) {
color[k] = use_machine({0, k});
list[color[k]].push_back(k);
k += 1;
} else {
if (list[0].size() >= 2) {
const int tmp = use_machine({list[0][0], k, list[0][1], k + 1});
color[k] = tmp / 2;
color[k + 1] = tmp % 2;
} else {
const int tmp = use_machine({list[1][0], k, list[1][1], k + 1});
color[k] = 1 - tmp / 2;
color[k + 1] = 1 - tmp % 2;
}
list[color[k]].push_back(k);
list[color[k + 1]].push_back(k + 1);
k += 2;
}
}
int ret = std::count(color.begin(), color.begin() + k, 0);
while (k < n) {
const int fixed = list[0].size() >= list[1].size() ? 0 : 1;
const int l = k;
const int r = std::min(n, k + (int)list[fixed].size());
k = r;
vector<int> vec;
for (int i = l; i < r; ++i) {
vec.push_back(list[fixed][i - l]);
vec.push_back(i);
}
const int query = use_machine(vec);
if (fixed == 0) {
ret += (r - l) - (query + 1) / 2;
list[query % 2].push_back(r - 1);
} else {
ret += (query + 1) / 2;
list[1 - query % 2].push_back(r - 1);
}
}
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |