# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
143660 |
2019-08-14T20:15:56 Z |
MladenP |
Money (IZhO17_money) |
C++17 |
|
2 ms |
380 KB |
#include <bits/stdc++.h>
#define MAXN 1000010
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
using namespace std;
int a[MAXN], b[MAXN], inv[MAXN], N, l, r;
int R[MAXN];
vector<pii> seg;
int main() {
cin >> N;
for(int i = 1; i <= N; i++) cin >> a[i];
for(int i = 1; i <= N; i++) b[i-1] = a[i];
sort(b, b+N);
for(int i = 0; i < N; i++) inv[b[i]] = i+1;
for(int i = 1; i <= N; i++) a[i] = inv[a[i]];
l = r = a[1];
for(int i = 2; i <= N+1; i++) {
if(a[i] == r+1) {
r++;
} else {
seg.pb({l, r});
l = r = a[i];
}
}
int rez = 0;
while(!seg.empty()) {
pii vrh = seg.back();
seg.pop_back();
l = vrh.fi, r = vrh.se;
if(R[l-1]) {
l = R[l-1];
R[l-1] = 0;
while(!seg.empty()) {
pii vrh = seg.back();
if(vrh.se == l-1) {
seg.pop_back();
l = vrh.fi;
} else {
break;
}
}
seg.pb({l, r});
} else {
rez++;
R[r] = l;
}
}
cout << rez;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |