답안 #91123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91123 2018-12-26T10:12:31 Z emil_physmath Money (IZhO17_money) C++14
100 / 100
1498 ms 95396 KB
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
using namespace std;

int a[1000005], dp[1000005], l[1000005];

int main()
{
	int n;
	cin>>n;
	for (int k=0; k<n; k++)
		scanf("%d", a+k);
	set<int>curSorted;
	curSorted.insert(0);
	curSorted.insert(10000000);
	for (int i=0; i<n; i++)
	{
		l[i]=i;
		if (i && a[i-1]<=a[i])
			l[i]=l[i-1];
		for (int k=(i?l[i-1]:0); k<l[i]; k++)
			curSorted.insert(a[k]);
		dp[i]=i+1;
		auto rBound=curSorted.lower_bound(a[i]);
		int minVal=*--rBound;
		int k=lower_bound(a+l[i], a+i+1, minVal)-a;
		for (k; k<=i; k++)
			dp[i]=min(dp[i], (k?dp[k-1]:0)+1);
	}
	cout<<dp[n-1]<<'\n';
	//int i=0, ans=0;
	//set<int> curSorted;
	//curSorted.insert(0);
	//curSorted.insert(10000000);
	//while (i<n)
	//{
	//	ans++;
	//	int j=i;
	//	while (j+1<n && a[j+1]>a[j])
	//		j++;
	//	auto rBound=curSorted.upper_bound(a[i]);
	//	j=upper_bound(a+i, a+j+1, *rBound)-a;
	//	for (int k=i; k<j; k++)
	//		curSorted.insert(a[k]);
	//	i=j;
	//}
	//cout<<ans<<'\n';

	char I;
	cin >> I;
	return 0;
}
/*
9
2 5 4 3 5 6 4 6 7
5
1 2 4 3 5
*/

Compilation message

money.cpp: In function 'int main()':
money.cpp:29:9: warning: statement has no effect [-Wunused-value]
   for (k; k<=i; k++)
         ^
money.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a+k);
   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 2 ms 572 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 756 KB Output is correct
16 Correct 2 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 2 ms 572 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 756 KB Output is correct
16 Correct 2 ms 756 KB Output is correct
17 Correct 2 ms 756 KB Output is correct
18 Correct 2 ms 756 KB Output is correct
19 Correct 2 ms 756 KB Output is correct
20 Correct 2 ms 756 KB Output is correct
21 Correct 2 ms 756 KB Output is correct
22 Correct 2 ms 756 KB Output is correct
23 Correct 2 ms 756 KB Output is correct
24 Correct 2 ms 756 KB Output is correct
25 Correct 2 ms 756 KB Output is correct
26 Correct 2 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 2 ms 572 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 756 KB Output is correct
16 Correct 2 ms 756 KB Output is correct
17 Correct 2 ms 756 KB Output is correct
18 Correct 2 ms 756 KB Output is correct
19 Correct 2 ms 756 KB Output is correct
20 Correct 2 ms 756 KB Output is correct
21 Correct 2 ms 756 KB Output is correct
22 Correct 2 ms 756 KB Output is correct
23 Correct 2 ms 756 KB Output is correct
24 Correct 2 ms 756 KB Output is correct
25 Correct 2 ms 756 KB Output is correct
26 Correct 2 ms 756 KB Output is correct
27 Correct 2 ms 756 KB Output is correct
28 Correct 2 ms 756 KB Output is correct
29 Correct 2 ms 756 KB Output is correct
30 Correct 2 ms 756 KB Output is correct
31 Correct 2 ms 756 KB Output is correct
32 Correct 2 ms 756 KB Output is correct
33 Correct 2 ms 756 KB Output is correct
34 Correct 2 ms 756 KB Output is correct
35 Correct 2 ms 756 KB Output is correct
36 Correct 2 ms 756 KB Output is correct
37 Correct 2 ms 756 KB Output is correct
38 Correct 2 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 2 ms 572 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 756 KB Output is correct
16 Correct 2 ms 756 KB Output is correct
17 Correct 2 ms 756 KB Output is correct
18 Correct 2 ms 756 KB Output is correct
19 Correct 2 ms 756 KB Output is correct
20 Correct 2 ms 756 KB Output is correct
21 Correct 2 ms 756 KB Output is correct
22 Correct 2 ms 756 KB Output is correct
23 Correct 2 ms 756 KB Output is correct
24 Correct 2 ms 756 KB Output is correct
25 Correct 2 ms 756 KB Output is correct
26 Correct 2 ms 756 KB Output is correct
27 Correct 2 ms 756 KB Output is correct
28 Correct 2 ms 756 KB Output is correct
29 Correct 2 ms 756 KB Output is correct
30 Correct 2 ms 756 KB Output is correct
31 Correct 2 ms 756 KB Output is correct
32 Correct 2 ms 756 KB Output is correct
33 Correct 2 ms 756 KB Output is correct
34 Correct 2 ms 756 KB Output is correct
35 Correct 2 ms 756 KB Output is correct
36 Correct 2 ms 756 KB Output is correct
37 Correct 2 ms 756 KB Output is correct
38 Correct 2 ms 756 KB Output is correct
39 Correct 79 ms 8944 KB Output is correct
40 Correct 141 ms 18020 KB Output is correct
41 Correct 62 ms 18020 KB Output is correct
42 Correct 63 ms 18020 KB Output is correct
43 Correct 46 ms 18088 KB Output is correct
44 Correct 172 ms 33684 KB Output is correct
45 Correct 166 ms 40400 KB Output is correct
46 Correct 171 ms 47108 KB Output is correct
47 Correct 149 ms 48172 KB Output is correct
48 Correct 155 ms 48192 KB Output is correct
49 Correct 696 ms 66668 KB Output is correct
50 Correct 641 ms 66756 KB Output is correct
51 Correct 658 ms 66756 KB Output is correct
52 Correct 689 ms 66820 KB Output is correct
53 Correct 596 ms 66820 KB Output is correct
54 Correct 558 ms 66820 KB Output is correct
55 Correct 1202 ms 95300 KB Output is correct
56 Correct 1220 ms 95300 KB Output is correct
57 Correct 1302 ms 95356 KB Output is correct
58 Correct 1457 ms 95356 KB Output is correct
59 Correct 1455 ms 95356 KB Output is correct
60 Correct 1498 ms 95396 KB Output is correct
61 Correct 1485 ms 95396 KB Output is correct
62 Correct 1274 ms 95396 KB Output is correct