# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
342885 |
2021-01-03T06:43:53 Z |
maskoff |
Money (IZhO17_money) |
C++17 |
|
1 ms |
384 KB |
#include <bits/stdc++.h>
#define file ""
#define all(x) x.begin(), x.end()
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll inf = 1e18 + 5;
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;
int dx[] = {+1, 0, -1, 0};
int dy[] = {0, +1, 0, -1};
int n;
int a[N];
void solve1() {
int res = 40;
for (int mask = 1; mask < (1 << n); mask += 2) {
//cerr << mask << endl;
vector<int> v[20];
int cur = 0;
for (int i = 0; i < n; i++) {
if (mask & (1 << i)) v[++cur].pb(a[i + 1]);
else v[cur].pb(a[i + 1]);
}
vector<int> ans;
for (int to : v[1]) ans.pb(to);
if (!is_sorted(all(ans))) continue;
for (int i = 2; i <= cur; i++) {
//cerr << "i : " << i << endl;
for (int p = 0; p <= ans.size(); p++) {
vector<int> d = ans;
//cerr << "p : " << p << endl;
for (int j = 0; j < v[i].size(); j++)
d.insert(d.begin() + p + j, v[i][j]);
//for (int to : d) cerr << to << " ";
//cerr << endl;
if (is_sorted(all(d))) {
ans = d;
goto pos;
}
}
goto here;
pos:;
}
res = min(res, cur);
here:;
}
cout << res;
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
srand(time(nullptr));
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
if (n < 8) solve1();
return 0;
}
Compilation message
money.cpp: In function 'void solve1()':
money.cpp:44:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int p = 0; p <= ans.size(); p++) {
| ~~^~~~~~~~~~~~~
money.cpp:47:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int j = 0; j < v[i].size(); j++)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |