Submission #37670

# Submission time Handle Problem Language Result Execution time Memory
37670 2017-12-26T19:06:37 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,h=0;
	cin>>n;
	for (int i = 0; i < n; i++){
		int k;
		cin>>k;
		if (i!=0 & k==a[h-1].first){
            continue;
		}
		a[h].first=k;
		a[h].second=i;
		h++;
	}
	n=h;

	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;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:33:8: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   if (i!=0 & k==a[h-1].first){
        ^
# 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 Incorrect 0 ms 10964 KB Output isn't correct
8 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 Incorrect 0 ms 10964 KB Output isn't correct
8 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 Incorrect 0 ms 10964 KB Output isn't correct
8 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 Incorrect 0 ms 10964 KB Output isn't correct
8 Halted 0 ms 0 KB -