Submission #385778

# Submission time Handle Problem Language Result Execution time Memory
385778 2021-04-05T00:09:45 Z SansPapyrus683 Global Warming (CEOI18_glo) C++17
100 / 100
120 ms 3172 KB
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::vector;
/**
 * https://oj.uz/problem/view/CEOI18_glo
 * 8 10
 * 7 3 5 12 2 7 3 4 should output 5
 */
int main() {
    int temp_num;
    int max_cheating;
    std::cin >> temp_num >> max_cheating;
    vector<int> temps(temp_num);
    for (int t = 0; t < temp_num; t++) {
        std::cin >> temps[t];
    }
    
    vector<int> pref_longest(temp_num);
    vector<int> min_endings;
    for (int i = 0; i < temp_num; i++) {
        int t = temps[i];
		int pos = std::lower_bound(min_endings.begin(), min_endings.end(), t) - min_endings.begin();
		if (pos == min_endings.size()) {
            min_endings.push_back(t);
        } else {
            min_endings[pos] = t;
        }
        pref_longest[i] = pos + 1;
	}

    int longest = 0;
    vector<int> max_begins;
    for (int i = temp_num - 1; i >= 0; i--) {
        int t = temps[i];
        // negative to keep the binary search happy
        int pos = std::lower_bound(max_begins.begin(), max_begins.end(), -t) - max_begins.begin();
        longest = std::max(longest, pref_longest[i] + pos);
        
        int insert_pos = std::lower_bound(
            max_begins.begin(), max_begins.end(), -t - max_cheating
        ) - max_begins.begin();
        if (insert_pos == max_begins.size()) {
            max_begins.push_back(-t - max_cheating);
        } else {
            max_begins[insert_pos] = -t - max_cheating;
        }
    }
    cout << longest << endl;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:27:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   if (pos == min_endings.size()) {
      |       ~~~~^~~~~~~~~~~~~~~~~~~~~
glo.cpp:46:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if (insert_pos == max_begins.size()) {
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 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 380 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 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 380 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 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 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 380 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 384 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 384 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 1900 KB Output is correct
2 Correct 118 ms 1900 KB Output is correct
3 Correct 120 ms 1900 KB Output is correct
4 Correct 120 ms 1900 KB Output is correct
5 Correct 72 ms 3172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 748 KB Output is correct
2 Correct 31 ms 748 KB Output is correct
3 Correct 29 ms 748 KB Output is correct
4 Correct 19 ms 1004 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 18 ms 1004 KB Output is correct
7 Correct 27 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 1132 KB Output is correct
2 Correct 54 ms 1144 KB Output is correct
3 Correct 110 ms 1900 KB Output is correct
4 Correct 73 ms 3172 KB Output is correct
5 Correct 36 ms 1644 KB Output is correct
6 Correct 71 ms 2916 KB Output is correct
7 Correct 91 ms 2916 KB Output is correct
8 Correct 52 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 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 380 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 384 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 384 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 119 ms 1900 KB Output is correct
28 Correct 118 ms 1900 KB Output is correct
29 Correct 120 ms 1900 KB Output is correct
30 Correct 120 ms 1900 KB Output is correct
31 Correct 72 ms 3172 KB Output is correct
32 Correct 30 ms 748 KB Output is correct
33 Correct 31 ms 748 KB Output is correct
34 Correct 29 ms 748 KB Output is correct
35 Correct 19 ms 1004 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 18 ms 1004 KB Output is correct
38 Correct 27 ms 748 KB Output is correct
39 Correct 54 ms 1132 KB Output is correct
40 Correct 54 ms 1144 KB Output is correct
41 Correct 110 ms 1900 KB Output is correct
42 Correct 73 ms 3172 KB Output is correct
43 Correct 36 ms 1644 KB Output is correct
44 Correct 71 ms 2916 KB Output is correct
45 Correct 91 ms 2916 KB Output is correct
46 Correct 52 ms 1132 KB Output is correct
47 Correct 59 ms 1132 KB Output is correct
48 Correct 58 ms 1132 KB Output is correct
49 Correct 119 ms 2028 KB Output is correct
50 Correct 73 ms 3044 KB Output is correct
51 Correct 60 ms 2660 KB Output is correct
52 Correct 77 ms 3044 KB Output is correct
53 Correct 73 ms 3172 KB Output is correct
54 Correct 99 ms 3044 KB Output is correct
55 Correct 108 ms 1900 KB Output is correct