답안 #341592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341592 2020-12-30T07:00:38 Z nandonathaniel Money (IZhO17_money) C++14
100 / 100
1412 ms 62060 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e6+5;
int a[MAXN],dp[MAXN],mini,maxi,kel[MAXN],terakhir[MAXN];
 
set<int> S;
//set<int> active;
set<int>::iterator kelL,kelR;
//vector<set<int>::iterator> hapus;

bool valid(){
	if(mini==maxi)return true;
	kelR=S.lower_bound(maxi);
	return kelL==kelR;
}
 
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];
	int last=1,idx=0;
	for(int i=1;i<=n;i++){
		if(i==n || a[i]>a[i+1]){
			idx++;
			for(int j=last;j<=i;j++)kel[j]=idx;
			last=i+1;
			terakhir[idx]=i;
		}
		dp[i]=1e9;
	}
	S.insert(0);
	S.insert(1e6+5);
	for(int i=0;i<n;i++){
		int ki=i+1,ka=terakhir[kel[i+1]],res=-1;
		mini=a[ki];
		kelL=S.upper_bound(mini);
		while(ki<=ka){
			int mid=(ki+ka)/2;
			maxi=a[mid];
			if(valid()){
				res=mid;
				ki=mid+1;
			}
			else ka=mid-1;
		}
		//Ini gtw proofnya knp ga TLE, apa emang haram?
		for(int j=i+1;j<=res;j++)dp[j]=min(dp[j],dp[i]+1);
//		auto itL=active.lower_bound(i+1),itR=active.upper_bound(res);
//		for(auto it=itL;it!=itR;++it){
//			dp[*it]=min(dp[*it],dp[i]+1);
//			hapus.push_back(it);
//		}
//		for(auto isi : hapus)active.erase(isi);
//		hapus.clear();
//		jadi TLE kalau ga looping
		S.insert(a[i+1]);
	}
	printf("%d\n",dp[n]);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 236 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 236 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 72 ms 6764 KB Output is correct
40 Correct 124 ms 10988 KB Output is correct
41 Correct 58 ms 5484 KB Output is correct
42 Correct 56 ms 4972 KB Output is correct
43 Correct 42 ms 3692 KB Output is correct
44 Correct 148 ms 13932 KB Output is correct
45 Correct 146 ms 13804 KB Output is correct
46 Correct 177 ms 13784 KB Output is correct
47 Correct 130 ms 13036 KB Output is correct
48 Correct 144 ms 13420 KB Output is correct
49 Correct 690 ms 32500 KB Output is correct
50 Correct 684 ms 32236 KB Output is correct
51 Correct 667 ms 32492 KB Output is correct
52 Correct 623 ms 32364 KB Output is correct
53 Correct 623 ms 32236 KB Output is correct
54 Correct 636 ms 32364 KB Output is correct
55 Correct 1383 ms 61164 KB Output is correct
56 Correct 1405 ms 61804 KB Output is correct
57 Correct 1368 ms 62060 KB Output is correct
58 Correct 1393 ms 61932 KB Output is correct
59 Correct 1390 ms 61824 KB Output is correct
60 Correct 1365 ms 61812 KB Output is correct
61 Correct 1364 ms 61932 KB Output is correct
62 Correct 1412 ms 61752 KB Output is correct