# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1019313 | Boas | 버섯 세기 (IOI20_mushrooms) | C++17 | 1 ms | 344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "mushrooms.h"
#define loop(x, i) for (int i = 0; i < x; i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef set<int> si;
typedef vector<vi> vvi;
#define getX (max((int)A.size(), (int)B.size()))
int count_mushrooms(int n)
{
vi A = {0}, B;
int c1 = use_machine({0, 1});
int i = 2;
if (c1 == 1)
{
if (n == 2)
return 1;
B.pb(1);
int c2 = use_machine({1, 2});
i++;
if (c2 == 1)
A.pb(2);
else
B.pb(2);
}
else
{
A.pb(1);
}
while (getX < sqrt((double)n))
{
if (A.size() >= 2)
{
if (i + 1 >= n)
break;
int res = use_machine({A[0], i, A[1], i + 1});
if (res == 0)
{
A.pb(i);
A.pb(i + 1);
}
else if (res == 1)
{
A.pb(i);
B.pb(i + 1);
}
else if (res == 2)
{
A.pb(i + 1);
B.pb(i);
}
else
{
B.pb(i);
B.pb(i + 1);
}
i += 2;
}
else
{
if (i + 1 >= n)
break;
int res = use_machine({B[0], i, B[1], i + 1});
if (res == 3)
{
A.pb(i);
A.pb(i + 1);
}
else if (res == 2)
{
A.pb(i);
B.pb(i + 1);
}
else if (res == 1)
{
A.pb(i + 1);
B.pb(i);
}
else
{
B.pb(i + 1);
B.pb(i);
}
i += 2;
}
}
if (i == n - 1)
{
if (use_machine({0, i}) == 0)
A.pb(i);
i++;
}
int res = A.size();
for (; i < n;)
{
int x = getX;
vi q;
if (A.size() >= B.size())
{
int l = min(2 * getX - 2, n - i);
for (int j = 0; j + 1 < l; j += 2)
{
q.pb(A.at(j / 2));
q.pb(i + j);
q.pb(i + j + 1);
}
q.pb(A.at(l / 2));
int c3 = use_machine(q);
res += l - c3;
if (l % 2 == 1)
{
res--;
int c3 = use_machine({0, n - 1});
if (c3 == 0)
res++;
}
q.clear();
}
else
{
int l = min(2 * getX - 2, n - i);
for (int j = 0; j + 1 < l; j += 2)
{
q.pb(B.at(j / 2));
q.pb(i + j);
q.pb(i + j + 1);
}
q.pb(B.at(l / 2));
int c3 = use_machine(q);
res += c3;
if (l % 2 == 1)
{
int c3 = use_machine({0, n - 1});
if (c3 == 0)
res++;
}
q.clear();
}
i += x;
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |