# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
800495 | QwertyPi | 버섯 세기 (IOI20_mushrooms) | C++14 | 6 ms | 324 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "mushrooms.h"
std::vector<int> a[2];
int b[2];
int id, n;
void query_1(){
if(id >= n) return;
std::vector<int> m {0, id};
int c = use_machine(m);
a[c].push_back(id);
id++;
}
void query_2(){
if(id >= n) return;
if(a[0].size() <= 1 && a[1].size() <= 1 || id == n - 1){ query_1(); return; }
int majority = a[0].size() >= a[1].size() ? 0 : 1;
std::vector<int> m = {a[majority][0], id, a[majority][1], id + 1};
int c = use_machine(m);
id += 2;
a[majority ^ (c / 2)].push_back(m[1]);
a[majority ^ (c % 2)].push_back(m[3]);
}
void query_3(){
if(id >= n) return;
if(a[0].size() <= 1 && a[1].size() <= 1){ query_1(); return; }
int majority = a[0].size() >= a[1].size() ? 0 : 1;
int k = a[majority].size(); k = std::min(k, n - id);
std::vector<int> m;
for(int i = id; i < id + k; i++){
m.push_back(a[majority][i - id]); m.push_back(i);
}
int c = use_machine(m);
id += k;
a[majority ^ (c % 2)].push_back(m.back());
b[majority ^ 1] += c / 2;
b[majority] += (k - 1) - c / 2;
}
void query_4(){
if(id >= n) return;
if(a[0].size() <= 2 && a[1].size() <= 2 || n - id <= 5){ query_1(); return; }
int majority = a[0].size() >= a[1].size() ? 0 : 1;
std::vector<int> m1 {a[majority][0], id, a[majority][1], id + 1, a[majority][2], id + 2};
int c1 = use_machine(m1);
a[majority ^ (c1 % 2)].push_back(id + 2);
if(c1 / 2 == 2){
a[majority ^ 1].push_back(id);
a[majority ^ 1].push_back(id + 1);
id += 3;
}else if(c1 / 2 == 0){
a[majority ^ 0].push_back(id);
a[majority ^ 0].push_back(id + 1);
id += 3;
}else{
std::vector<int> m2 {a[majority][0], id, a[majority][1], id + 3};
int c2 = use_machine(m2);
a[majority ^ (c2 % 2)].push_back(id + 3);
a[majority ^ (c2 / 2)].push_back(id);
a[majority ^ !(c2 / 2)].push_back(id + 1);
id += 4;
}
}
int count_mushrooms(int N) {
a[0].clear(); a[1].clear(); b[0] = b[1] = 0;
n = N; a[0].push_back(0); id = 1;
if(n <= 1000){
while(id < n) query_3();
return a[0].size() + b[0];
}
int SQ = 132;
while(id < SQ) query_4();
while(id < n) query_3();
return a[0].size() + b[0];
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |