# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1055596 | Trent | 버섯 세기 (IOI20_mushrooms) | C++17 | 18 ms | 2644 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "mushrooms.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;
typedef vector<ll> vll;
typedef set<int> si;
int count_mushrooms(int n) {
int IVL = 120;
vi chk;
for(int i = 0; i < n; i += IVL) chk.push_back(i);
if(chk.back() < n-1) chk.push_back(n-1);
vi ty(chk.size());
ty[0] = 0;
REP(i, 1, chk.size()) {
vi tst = {0, chk[i]};
ty[i] = use_machine(tst) == 0 ? 0 : 1;
}
vi ac, bc;
forR(i, chk.size()) {
if(ty[i] == 0) ac.push_back(chk[i]);
else bc.push_back(chk[i]);
}
vb usd(n, false);
for(int i : chk) usd[i] = true;
vector<si> ai(ac.size()), bi(bc.size());
forR(i, (int) ac.size() - 1) for(int j = ac[i] + 1; j < ac[i+1]; ++j) if(!usd[j]) ai[i].insert(j);
forR(i, (int) bc.size() - 1) for(int j = bc[i] + 1; j < bc[i+1]; ++j) if(!usd[j]) bi[i].insert(j);
vi ain(n, -1), bin(n, -1);
forR(i, ai.size()) for(int j : ai[i]) ain[j] = i;
forR(i, bi.size()) for(int j : bi[i]) bin[j] = i;
si ane, bne;
forR(i, ai.size()) if(!ai[i].empty()) ane.insert(i);
forR(i, bi.size()) if(!bi[i].empty()) bne.insert(i);
int tot = (int) ac.size();
while(!ane.empty() || !bne.empty()){
si qus;
if(ane.size() >= bne.size()) {
for(int i : ane) {
qus.insert(ac[i]);
qus.insert(ac[i+1]);
qus.insert(*ai[i].begin());
}
vi qu;
for(int i : qus) qu.push_back(i);
int res = use_machine(qu);
cerr << qu.size() << ' ' << res << '\n';
tot += (int) ane.size() - res / 2;
} else {
for(int i : bne) {
qus.insert(bc[i]);
qus.insert(bc[i+1]);
qus.insert(*bi[i].begin());
}
vi qu;
for(int i : qus) qu.push_back(i);
int res = use_machine(qu);
cerr << qu.size() << ' ' << res << '\n';
tot += res / 2;
}
for(int i : qus) {
if(!usd[i]) {
usd[i] = true;
if(ain[i] != -1) {
ai[ain[i]].erase(i);
if(ai[ain[i]].empty()) ane.erase(ain[i]);
}
if(bin[i] != -1) {
bi[bin[i]].erase(i);
if(bi[bin[i]].empty()) bne.erase(bin[i]);
}
}
}
}
forR(i, n) if(!usd[i]) {
tot += use_machine({0, i}) == 0 ? 1 : 0;
}
return tot;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |