# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
169790 |
2019-12-22T21:09:15 Z |
super_j6 |
Money (IZhO17_money) |
C++14 |
|
3 ms |
376 KB |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
const int maxn = 1000000;
int n;
pi a[maxn];
bool used[maxn];
stack<int> stk;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i].first;
a[i].second = i;
}
sort(a, a + n);
int ret = 0;
for(int i = 0; i < n; i++){
if(stk.empty() || !a[i].second || !used[a[i].second - 1]){
stk.push(a[i].second);
used[a[i].second] = 1;
}else{
while(stk.top() != a[i].second - 1){
used[stk.top()] = 0;
stk.pop();
ret++;
}
used[stk.top()] = 0;
stk.pop();
stk.push(a[i].second);
used[a[i].second] = 1;
}
}
ret += stk.size();
cout << ret << endl;
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 |
376 KB |
Output is correct |
4 |
Incorrect |
3 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 |
376 KB |
Output is correct |
4 |
Incorrect |
3 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 |
376 KB |
Output is correct |
4 |
Incorrect |
3 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 |
376 KB |
Output is correct |
4 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |