Submission #37669

# Submission time Handle Problem Language Result Execution time Memory
37669 2017-12-26T18:55:27 Z Abelyan Money (IZhO17_money) C++14
0 / 100
0 ms 10964 KB
#include <bits/stdc++.h>
using namespace std;

const int N=1000006;
pair <int,int> a[N];
bool r[N];
int ans=1;

void check(int i,int mi){
    if (r[a[i].second]){
        r[a[mi].second+1]=false;
        r[a[i].second+1]=true;
    }
    else{
        if (a[i].second < a[mi].second){
            r[a[mi].second + 1] = false;
            r[a[i].second + 1] = true;
        }
        else{
            r[a[i].second + 1] = true;
        }
        ans++;
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	int n,j;
	cin>>n;
	for (int i = 0; i < n; i++){
		int k;
		cin>>k;
		a[i].first=k;
		a[i].second=i;
	}
	sort(a,a+n);
	r[a[0].second+1]=true;
	j=1;
	while (a[j].first==a[j-1].first){
        check(j,j-1);
        j++;
	}

	while(j<n){
        //cout<<j<<endl;
        int l=j;
        j++;
        while (a[j].first==a[j-1].first){
            j++;
        }
        j--;
        int k=j;
        bool mb=false;
        //cout<<r[a[4].second]<<endl;
        while (r[a[j].second]){
            if (j==k){
                check(j,l-1);
                //cout<<"Alex"<<endl;
                mb=true;
            }
            else check(j,j+1);
            j--;
        }

        for (int i=l;i<=j;i++){
            if (i==l && mb){
                check(i,j+1);
            }
            else{
                //cout<<"alex"<<endl;
                check(i,i-1);
            }
        }
        j=k+1;
	}
	cout<<ans<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10964 KB Output is correct
2 Correct 0 ms 10964 KB Output is correct
3 Correct 0 ms 10964 KB Output is correct
4 Correct 0 ms 10964 KB Output is correct
5 Correct 0 ms 10964 KB Output is correct
6 Correct 0 ms 10964 KB Output is correct
7 Correct 0 ms 10964 KB Output is correct
8 Correct 0 ms 10964 KB Output is correct
9 Correct 0 ms 10964 KB Output is correct
10 Correct 0 ms 10964 KB Output is correct
11 Correct 0 ms 10964 KB Output is correct
12 Correct 0 ms 10964 KB Output is correct
13 Incorrect 0 ms 10964 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10964 KB Output is correct
2 Correct 0 ms 10964 KB Output is correct
3 Correct 0 ms 10964 KB Output is correct
4 Correct 0 ms 10964 KB Output is correct
5 Correct 0 ms 10964 KB Output is correct
6 Correct 0 ms 10964 KB Output is correct
7 Correct 0 ms 10964 KB Output is correct
8 Correct 0 ms 10964 KB Output is correct
9 Correct 0 ms 10964 KB Output is correct
10 Correct 0 ms 10964 KB Output is correct
11 Correct 0 ms 10964 KB Output is correct
12 Correct 0 ms 10964 KB Output is correct
13 Incorrect 0 ms 10964 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10964 KB Output is correct
2 Correct 0 ms 10964 KB Output is correct
3 Correct 0 ms 10964 KB Output is correct
4 Correct 0 ms 10964 KB Output is correct
5 Correct 0 ms 10964 KB Output is correct
6 Correct 0 ms 10964 KB Output is correct
7 Correct 0 ms 10964 KB Output is correct
8 Correct 0 ms 10964 KB Output is correct
9 Correct 0 ms 10964 KB Output is correct
10 Correct 0 ms 10964 KB Output is correct
11 Correct 0 ms 10964 KB Output is correct
12 Correct 0 ms 10964 KB Output is correct
13 Incorrect 0 ms 10964 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10964 KB Output is correct
2 Correct 0 ms 10964 KB Output is correct
3 Correct 0 ms 10964 KB Output is correct
4 Correct 0 ms 10964 KB Output is correct
5 Correct 0 ms 10964 KB Output is correct
6 Correct 0 ms 10964 KB Output is correct
7 Correct 0 ms 10964 KB Output is correct
8 Correct 0 ms 10964 KB Output is correct
9 Correct 0 ms 10964 KB Output is correct
10 Correct 0 ms 10964 KB Output is correct
11 Correct 0 ms 10964 KB Output is correct
12 Correct 0 ms 10964 KB Output is correct
13 Incorrect 0 ms 10964 KB Output isn't correct
14 Halted 0 ms 0 KB -