| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1357260 | kawhiet | Money (IZhO17_money) | C++20 | 51 ms | 452 KiB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
assert(n <= 20);
int ans = n;
for (int s = 0; s < (1 << n); s++) {
if (!(s & (1 << (n - 1)))) continue;
bool ok = true;
vector<int> b = {0, (int)1e9};
vector<int> c;
for (int i = 0; i < n; i++) {
c.push_back(a[i]);
if (s & (1 << i)) {
if (!ranges::is_sorted(c)) {
ok = false;
break;
}
int x = c[0], y = c.back();
bool found = false;
for (int i = 1; i < b.size(); i++) {
if (b[i - 1] <= x && y <= b[i]) {
found = true;
b.insert(b.begin() + i, c.begin(), c.end());
break;
}
}
if (!found) {
ok = false;
break;
}
c.clear();
}
}
if (ok) {
ans = min(ans, __builtin_popcount(s));
}
}
cout << ans << '\n';
return 0;
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
