# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168597 | Gurban | Money (IZhO17_money) | C++14 | 2 ms | 376 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>
#define pb push_back
#define ss second
#define ff first
#define N 2000006
#define inf 1000000009
#define ll long long
#define mid(a,b) (a+b)/2
using namespace std;
int n,a[N],sub,vis[N],pos,mn = 1e9;
map<int,int> p;
vector <pair<int,int>> v;
void fn(int ind,int pr){
if(p[ind] == 0)
return;
if(vis[p[ind]])
return;
if(ind + 1 != p[ind]) sub++;
if(ind + 1 != p[ind] and a[ind + 1] > a[ind] and a[ind + 1] <= pr){
vis[ind + 1] = 1;
pr = a[ind + 1];
fn(ind + 1,1e9);
}
fn(p[ind],pr);
}
int main()
{
scanf("%d",&n);
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
v.pb({a[i],i});
if(a[i] < mn){
mn = a[i];
pos = i;
}
}
sort(v.begin(),v.end());
for(int i = 0;i < v.size() - 1;i++)
p[v[i].ss] = v[i + 1].ss;
a[n + 1] = -1e9;
sub++;
fn(pos,1e9);
printf("%d",sub);
}
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... |