# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
873047 |
2023-11-14T11:05:28 Z |
c2zi6 |
Money (IZhO17_money) |
C++14 |
|
301 ms |
592 KB |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
bool test(VVI& v) {
set<int> st;
for (VI a : v) {
for (int i = 1; i < a.size(); i++) {
if (a[i-1] > a[i]) return false;
}
auto it = st.upper_bound(a[0]);
if (it != st.end() && *it < a.back()) return false;
for (int x : a) st.insert(x);
}
return true;
}
int dandax(VI a) {
VVI v;
int n = a.size();
int ret = n;
for (int s = 0; s < (1<<n); s += 2) {
v.clear();
rep(i, n) {
if (s & (1<<i)) v.back().pb(a[i]);
else v.pb(VI{a[i]});
}
if (test(v)) setmin(ret, (int)v.size());
continue;
for (VI vec : v) {
for (int x : vec) cout << x << " ";
cout << "| ";
} cout << (test(v) ? "TRUE" : "FALSE") << endl;
}
return ret;
}
void solve() {
int n;
cin >> n;
VI a(n);
for (int& x : a) cin >> x;
cout << dandax(a) << endl;
return;
dandax(a);
vector<bool> ka(1e6+1);
int ans = 1;
ka[a[0]] = true;
for (int i = 1; i < n; i++) {
if (a[i] < a[i-1]) {
ans++;
} else {
bool fl = false;
replr(j, a[i-1]+1, a[i]-1) fl |= ka[j];
if (fl) ans++;
}
ka[a[i]] = true;
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
/* freopen("248.in", "r", stdin); */
/* freopen("248.out", "w", stdout); */
int t = 1;
/* cin >> t; */
while (t--) solve();
}
Compilation message
money.cpp: In function 'bool test(VVI&)':
money.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 1; i < a.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
7 ms |
416 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
249 ms |
348 KB |
Output is correct |
21 |
Correct |
262 ms |
592 KB |
Output is correct |
22 |
Correct |
296 ms |
440 KB |
Output is correct |
23 |
Correct |
258 ms |
440 KB |
Output is correct |
24 |
Correct |
301 ms |
348 KB |
Output is correct |
25 |
Correct |
254 ms |
436 KB |
Output is correct |
26 |
Correct |
267 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
7 ms |
416 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
249 ms |
348 KB |
Output is correct |
21 |
Correct |
262 ms |
592 KB |
Output is correct |
22 |
Correct |
296 ms |
440 KB |
Output is correct |
23 |
Correct |
258 ms |
440 KB |
Output is correct |
24 |
Correct |
301 ms |
348 KB |
Output is correct |
25 |
Correct |
254 ms |
436 KB |
Output is correct |
26 |
Correct |
267 ms |
436 KB |
Output is correct |
27 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
7 ms |
416 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
249 ms |
348 KB |
Output is correct |
21 |
Correct |
262 ms |
592 KB |
Output is correct |
22 |
Correct |
296 ms |
440 KB |
Output is correct |
23 |
Correct |
258 ms |
440 KB |
Output is correct |
24 |
Correct |
301 ms |
348 KB |
Output is correct |
25 |
Correct |
254 ms |
436 KB |
Output is correct |
26 |
Correct |
267 ms |
436 KB |
Output is correct |
27 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |