# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1103546 |
2024-10-21T08:19:29 Z |
stdfloat |
Money (IZhO17_money) |
C++17 |
|
1 ms |
336 KB |
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (auto &i : a) {
cin >> i; i--;
}
int mn = INT_MAX;
for (int mk = 0; mk < 1 << (n - 1); mk++) {
vector<pii> v;
bool tr = true;
int pre = -1, cnt = 0;
for (int i = 0; i < n && tr; i++) {
if (i != n - 1 && !((mk >> i) & 1)) continue;
for (int j = pre + 1; j < i && tr; j++) {
tr = (a[j] <= a[j + 1]);
v.push_back({a[j], a[j + 1]});
}
cnt++; pre = i;
}
if (!tr) continue;
for (int i = 0; i < sz(v) && tr; i++) {
for (int j = 0; j < sz(v) && tr; j++)
tr = ((v[i].ff <= v[j].ff && v[j].ss <= v[i].ss) || (v[j].ff <= v[i].ff && v[i].ss <= v[j].ss) || max(v[i].ff, v[j].ff) >= min(v[i].ss, v[j].ss));
}
if (tr) mn = min(mn, cnt);
}
cout << mn;
return 0;
for (int mk = 0; mk < 1 << (n - 1); mk++) {
vector<pii> v;
bool tr = true;
int pre = -1, cnt = 0;
for (int i = 0; i < n && tr; i++) {
if (i != n - 1 && !((mk >> i) & 1)) continue;
for (int j = pre + 1; j < i && tr; j++) {
tr = (a[j] <= a[j + 1]);
v.push_back({a[j], a[j + 1]});
}
cnt++; pre = i;
}
if (!tr) continue;
for (int i = 0; i < sz(v) && tr; i++) {
for (int j = 0; j < sz(v) && tr; j++) {
if ((v[i].ff > v[j].ff || v[j].ss > v[i].ss) && (v[j].ff > v[i].ff || v[i].ss > v[j].ss) && max(v[i].ff, v[j].ff) < min(v[i].ss, v[j].ss)) tr = false;
}
}
if (tr && mn == cnt) {
cout << "\nmk " << mk << '\n';
for (int j = 0; j < n - 1; j++)
cout << ((mk >> j) & 1) << ' ';
cout << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |