# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1234087 | madamadam3 | Counting Mushrooms (IOI20_mushrooms) | C++20 | 0 ms | 0 KiB |
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(x) (cout << (x))
#else
#define dbg(x)
#endif
using vi =vector<int>;
#define pb push_back
#define FOR(i, a, b) for (int i = a; i < b; i++)
int count_mushrooms(int n) {
if (n <= 200) {
int tl_a = 1;
for (int i = 1; i < n; i++) {
tl_a += 1 - use_machine({0, i});
}
return tl_a;
}
vi isa(n, 0); isa[0] = 1;
isa[1] = 1 - use_machine({0, 1});
isa[2] = 1 - use_machine({0, 2});
// isa[3] = 1 - use_machine({0, 3});
int tl_a = accumulate(isa.begin(), isa.end(), 0);
vi smallfilt(4); bool small_dark = false;
if (tl_a == 1) {
small_dark = true;
smallfilt[0] = 1; smallfilt[2] = 2;
} else if (isa[1]) {
smallfilt[0] = 0;
smallfilt[2] = 1;
} else if (isa[2]) {
smallfilt[0] = 0;
smallfilt[2] = 2;
} else {
smallfilt[0] = 0;
smallfilt[2] = 3;
}
for (int i = 3; i < 200; i+=2) {
smallfilt[1] = i; smallfilt[3] = i+1;
int cnt = use_machine(smallfilt);
if (cnt == 0) {
isa[i] = isa[i+1] = 1;
} else if (cnt == 3) {
isa[i] = isa[i+1] = 0;
} else if (cnt == 2) {
isa[i] = 0;
isa[i+1] = 1;
} else if (cnt == 1) {
isa[i] = 1;
isa[i+1] = 0;
}
if (small_dark) isa[i] = 1 - isa[i];
if (small_dark) isa[i+1] = 1 - isa[i+1];
}
tl_a = accumulate(isa.begin(), isa.end(), 0);
bool using_dark = tl_a < 100;
int first_light = 0, first_dark = 0; while (isa[first_dark]) first_dark++;
vi filter_base(199, using_dark ? first_dark : first_light);
int cur_pos = 0;
for (int i = 0; i < 200 && cur_pos < 200; i++) {
if (isa[i] == using_dark) continue;
filter_base[cur_pos] = i;
cur_pos += 2;
}
for (int i = 200; i < n; i += 99) {
int spots = min(99, n - i);
vi filter(filter_base.begin(), filter_base.end());
int ps = 1;
for (int j = i; j < i + spots; j++) {
filter[ps] = j;
ps += 2;
}
filter.resize(spots*2 + 1);
int tl_non = use_machine(filter) / 2;
if (using_dark) {
tl_a += tl_non;
} else {
tl_a += spots - tl_non;
}
}
return tl_a;
}
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(x) (cout << (x))
#else
#define dbg(x)
#endif
using vi =vector<int>;
#define pb push_back
#define FOR(i, a, b) for (int i = a; i < b; i++)
int count_mushrooms(int n) {
if (n <= 200) {
int tl_a = 1;
for (int i = 1; i < n; i++) {
tl_a += 1 - use_machine({0, i});
}
return tl_a;
}
vi isa(n, 0); isa[0] = 1;
isa[1] = 1 - use_machine({0, 1});
isa[2] = 1 - use_machine({0, 2});
// isa[3] = 1 - use_machine({0, 3});
int tl_a = accumulate(isa.begin(), isa.end(), 0);
vi smallfilt(4); bool small_dark = false;
if (tl_a == 1) {
small_dark = true;
smallfilt[0] = 1; smallfilt[2] = 2;
} else if (isa[1]) {
smallfilt[0] = 0;
smallfilt[2] = 1;
} else if (isa[2]) {
smallfilt[0] = 0;
smallfilt[2] = 2;
} else {
smallfilt[0] = 0;
smallfilt[2] = 3;
}
for (int i = 3; i < 200; i+=2) {
smallfilt[1] = i; smallfilt[3] = i+1;
int cnt = use_machine(smallfilt);
if (cnt == 0) {
isa[i] = isa[i+1] = 1;
} else if (cnt == 3) {
isa[i] = isa[i+1] = 0;
} else if (cnt == 2) {
isa[i] = 0;
isa[i+1] = 1;
} else if (cnt == 1) {
isa[i] = 1;
isa[i+1] = 0;
}
if (small_dark) isa[i] = 1 - isa[i];
if (small_dark) isa[i+1] = 1 - isa[i+1];
}
tl_a = accumulate(isa.begin(), isa.end(), 0);
bool using_dark = tl_a < 100;
int first_light = 0, first_dark = 0; while (isa[first_dark]) first_dark++;
vi filter_base(199, using_dark ? first_dark : first_light);
int cur_pos = 0;
for (int i = 0; i < 200 && cur_pos < 200; i++) {
if (isa[i] == using_dark) continue;
filter_base[cur_pos] = i;
cur_pos += 2;
}
for (int i = 200; i < n; i += 99) {
int spots = min(99, n - i);
vi filter(filter_base.begin(), filter_base.end());
int ps = 1;
for (int j = i; j < i + spots; j++) {
filter[ps] = j;
ps += 2;
}
filter.resize(spots*2 + 1);
int tl_non = use_machine(filter) / 2;
if (using_dark) {
tl_a += tl_non;
} else {
tl_a += spots - tl_non;
}
}
return tl_a;
}