Submission #341279

# Submission time Handle Problem Language Result Execution time Memory
341279 2020-12-29T10:49:15 Z nandonathaniel Money (IZhO17_money) C++14
0 / 100
1 ms 364 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e6+5;
int a[MAXN],dp[MAXN],mini,maxi;

set<int> S;

bool valid(){
	if(mini==maxi)return true;
	auto it=S.upper_bound(mini);
	auto it2=S.lower_bound(maxi);
	return it==it2;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)cin >> a[i];
	S.insert(0);
	S.insert(1e6+5);
	for(int i=1;i<=n;i++){
		dp[i]=1e9;
		mini=a[i];maxi=a[i];
		for(int j=i-1;j>=0;j--){
			if(valid())dp[i]=min(dp[i],dp[j]+1);
			mini=min(mini,a[j]);
			maxi=max(maxi,a[j]);
			if(a[j]>a[j+1])break;
		}
		S.insert(a[i]);
	}
	cout << dp[n] << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -