# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
702089 | grossly_overconfident | 버섯 세기 (IOI20_mushrooms) | C++17 | 8 ms | 336 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
/*
int uses = 0;
int use_machine(vector<int> v){
int count = 0;
uses++;
vector<int> shrooms =
for (int i = 1; i < v.size(); ++i){
if (shrooms[v[i]] != shrooms[v[i - 1]]){
count++;
}
}
return count;
}
*/
int count_mushrooms(int n) {
if (n < 220){
int a = 1;
for (int i = 1; i < n; ++i){
a += 1 - use_machine({ 0, i });
}
return a;
}
int asize = 1;
int bsize = 0;
vector<int> a(1, 0);
vector<int> b;
if (use_machine({ 0, 1 }) == 1){
b.push_back(1);
bsize++;
}
else{
a.push_back(1);
asize++;
}
if (use_machine({ 0, 2 }) == 1){
b.push_back(2);
bsize++;
}
else{
a.push_back(2);
asize++;
}
for (int i = 3; i <= 160; i += 2){
if (asize > bsize){
int h = use_machine({ i, a[0], i + 1, a[1]});
//cout << i << " " << a[0] << " " << i + 1 << " " << a[1] << " :: " << h << " :: a" << endl;
if (h == 0){
asize += 2;
a.push_back(i);
a.push_back(i + 1);
}
else if (h == 3){
bsize += 2;
b.push_back(i);
b.push_back(i + 1);
}
else{
bsize += 1;
asize += 1;
if (h == 1){
b.push_back(i);
a.push_back(i + 1);
}
else{
a.push_back(i);
b.push_back(i + 1);
}
}
}
else {
int h = use_machine({ i, b[0], i + 1, b[1] });
//cout << i << " " << b[0] << " " << i + 1 << " " << b[1] << " :: " << h << " :: b" << endl;
if (h == 0){
bsize += 2;
b.push_back(i);
b.push_back(i + 1);
}
else if (h == 3){
asize += 2;
a.push_back(i);
a.push_back(i + 1);
}
else{
bsize += 1;
asize += 1;
if (h == 1){
a.push_back(i);
b.push_back(i + 1);
}
else{
b.push_back(i);
a.push_back(i + 1);
}
}
}
}
/*
for (auto u : a){
cout << u << " ";
}
cout << endl << endl;
for (auto u : b){
cout << u << " ";
}
*/
int i = 161;
int tally = asize;
while (true){
if (a.size() < b.size()){
vector<int> p;
int w = i;
for (int j = 0; j < bsize; ++j){
p.push_back(i);
p.push_back(b[j]);
i++;
if (i == n){
break;
}
}
int h = use_machine(p);
if (h % 2 == 0){
b.push_back(w);
tally += h / 2;
bsize++;
}
else{
a.push_back(w);
tally++;
asize++;
tally += (h - 1) / 2;
}
if (i == n){
return tally;
}
}
else{
vector<int> p;
int w = i;
int psize = 0;
for (int j = 0; j < asize; ++j){
p.push_back(i);
p.push_back(a[j]);
psize++;
i++;
if (i == n){
break;
}
}
int h = use_machine(p);
if (h % 2 == 0){
a.push_back(w);
asize++;
tally++;
tally += (psize - 1) - (h / 2);
}
else{
b.push_back(w);
bsize++;
tally += (psize - 1) - ((h - 1) / 2);
}
if (i == n){
return tally;
}
}
if (i == n){
return tally;
}
}
}
/*
int main(){
int g = count_mushrooms(19002);
cout << endl << endl << g << endl << uses;
return 0;
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |