#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include "mushrooms.h"
using namespace std;
const int VAL = 141;
vector<int> a, b;
int count_mushrooms(int n) {
a.clear(); b.clear();
srand(time(NULL));
vector<int> v;
for (int i = 1; i < n; ++i)
v.push_back(i);
// random_shuffle(v.begin(), v.end());
int ans = 0, pos = 0;
a.push_back(0);
while (pos < (int) v.size()/*a.size() < VAL || b.size() < VAL*/) {
if (a.size() > 1) {
vector<int> arr = {a[0]};
if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;
arr.push_back(a[1]);
if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;
int ret = use_machine(arr);
if (ret & 2) {
b.push_back(arr[1]);
} else {
a.push_back(arr[1]);
}
if (ret & 1) {
b.push_back(arr[3]);
} else {
a.push_back(arr[3]);
}
} else if (b.size() > 1) {
vector<int> arr = {b[0]};
if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;
arr.push_back(b[1]);
if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;
int ret = use_machine(arr);
if (ret & 2) {
a.push_back(arr[1]);
} else {
b.push_back(arr[1]);
}
if (ret & 1) {
a.push_back(arr[3]);
} else {
b.push_back(arr[3]);
}
} else {
vector<int> arr = {a[0]};
if (pos < (int) v.size()) arr.push_back(v[pos]), ++pos;
int ret = use_machine(arr);
if (ret & 1) {
b.push_back(arr[1]);
} else {
a.push_back(arr[1]);
}
}
}
ans = a.size();
return ans;
}
// int count_mushrooms(int n) {
// int ans = 1;
// for (int i = 1; i < n; i += 2) {
// vector<int> v;
// if (i + 1 < n) v = {i, 0, i + 1};
// else v = {i, 0};
// int ret = use_machine(v);
// ans += (v.size() - 1) - ret;
// }
// return ans;
// }
// int main() {
// ios::sync_with_stdio(false);
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
0 ms |
256 KB |
Answer is not correct. |
3 |
Halted |
0 ms |
0 KB |
- |