# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
342800 | ivan_tudor | Money (IZhO17_money) | C++14 | 1598 ms | 51436 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int v[N];
multiset<int> ms;
void dbg(){
cerr<<ms.size()<<"\n";
for(auto x: ms)
cerr<<x<<" ";
cerr<<"\nok\n";
}
const int SIZE=1<<10;
char buffer[SIZE];
int point=SIZE;
inline char adv(){
if(point==SIZE){
fread(buffer,1,SIZE,stdin);
point=0;
}
return buffer[point++];
}
inline int read(){
char c;
int x=0,sgn=1;
c=adv();
while(isdigit(c)==false && c!='-')
c=adv();
while(c=='-'){
sgn*=-1;
c=adv();
}
while(isdigit(c)){
x=x*10+c-'0';
c=adv();
}
return x*sgn;
}
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n;
n = read();
for(int i=1;i<=n;i++){
v[i] = read();
ms.insert(v[i]);
}
int ans = 0;
for(int i= n; i>=1;){
int j = i;
ans++;
multiset<int>::iterator num = ms.find(v[i]);
while(j>=1 && v[j] == v[i]){
multiset<int>::iterator nxt = num;
num++;
ms.erase(nxt);
j--;
}
multiset<int>::iterator itr = num;
if(itr != ms.begin()){
itr = prev(itr);
while(j>=1 && v[j] == (*itr)){
j--;
if(itr == ms.begin()){
ms.erase(itr);
break;
}
multiset<int>::iterator newitr = itr;
newitr = prev(newitr);
ms.erase(itr);
itr = newitr;
}
}
i = j;
}
cout<<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |