Submission #879625

# Submission time Handle Problem Language Result Execution time Memory
879625 2023-11-27T18:43:44 Z alex_2008 Money (IZhO17_money) C++14
100 / 100
1036 ms 69784 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <fstream>
#include <random>
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N = 1e6 + 10;
int a[N], dp[N], down[N];
int f[N];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[0] = 0;
	dp[1] = 1;
	down[1] = 1;
	for (int i = 2; i <= n; i++) {
		down[i] = (a[i] < a[i - 1]) ? i : down[i - 1];
	}
	set <int> ms;
	for (int i = 1; i <= n; i++) {
		auto it = ms.upper_bound(a[i]);
		if (it == ms.end()) {
			f[i] = 10000000;
		}
		else f[i] = *it;
      	ms.insert(a[i]);
	}
	for (int i = 2; i <= n; i++) {
		int l = down[i], r = i;
		while (l <= r) {
			int mid = (l + r) / 2;			
			bool check = true;
			int R = 10000000;
			if (f[mid] < a[i]) check = false;
			if (check) {
				dp[i] = dp[mid - 1] + 1;
				r = mid - 1;
			}
			else l = mid + 1;
		}
	}
	cout << dp[n] << "\n";
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:49:8: warning: unused variable 'R' [-Wunused-variable]
   49 |    int R = 10000000;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 5 ms 6492 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 5 ms 6492 KB Output is correct
22 Correct 2 ms 6744 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 5 ms 6492 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 5 ms 6492 KB Output is correct
22 Correct 2 ms 6744 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6488 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6596 KB Output is correct
34 Correct 1 ms 6596 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 5 ms 6492 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 5 ms 6492 KB Output is correct
22 Correct 2 ms 6744 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6488 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6596 KB Output is correct
34 Correct 1 ms 6596 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 116 ms 14764 KB Output is correct
40 Correct 198 ms 20580 KB Output is correct
41 Correct 98 ms 17448 KB Output is correct
42 Correct 85 ms 17068 KB Output is correct
43 Correct 63 ms 16680 KB Output is correct
44 Correct 270 ms 22696 KB Output is correct
45 Correct 243 ms 22716 KB Output is correct
46 Correct 276 ms 22912 KB Output is correct
47 Correct 229 ms 22700 KB Output is correct
48 Correct 234 ms 22816 KB Output is correct
49 Correct 503 ms 41308 KB Output is correct
50 Correct 510 ms 41484 KB Output is correct
51 Correct 466 ms 41296 KB Output is correct
52 Correct 479 ms 41352 KB Output is correct
53 Correct 453 ms 41252 KB Output is correct
54 Correct 467 ms 41136 KB Output is correct
55 Correct 971 ms 69784 KB Output is correct
56 Correct 991 ms 69740 KB Output is correct
57 Correct 973 ms 69660 KB Output is correct
58 Correct 944 ms 69784 KB Output is correct
59 Correct 1008 ms 69784 KB Output is correct
60 Correct 1020 ms 69784 KB Output is correct
61 Correct 1036 ms 69784 KB Output is correct
62 Correct 1033 ms 69540 KB Output is correct