Submission #742153

# Submission time Handle Problem Language Result Execution time Memory
742153 2023-05-15T16:57:21 Z chanhchuong123 Global Warming (CEOI18_glo) C++14
100 / 100
57 ms 4284 KB
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)

template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}

const int dx[] = {-1, 0, 0, +1};
const int dy[] = {0, -1, +1, 0};

const int MAX = 200200;
int n, x;
int a[MAX];
int L[MAX];
int ans = 0;
vector<int> dp;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	if (fopen(task".inp", "r")) {
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}

	cin >> n >> x;
	for (int i = 1; i <= n; ++i) cin >> a[i];

	dp.clear();
	for (int i = 1; i <= n; ++i) {
        int pos = lower_bound(all(dp), a[i]) - dp.begin();
        if (pos == dp.size()) dp.push_back(a[i]);
        else dp[pos] = a[i]; L[i] = pos + 1;
        maximize(ans, L[i]);
	}

	dp.clear();
	for (int i = n; i >= 1; --i) {
        int POS = lower_bound(all(dp), -a[i] + x) - dp.begin();
        maximize(ans, L[i] + POS);

        int pos = lower_bound(all(dp), -a[i]) - dp.begin();
        if (pos == dp.size()) dp.push_back(-a[i]);
        else dp[pos] = -a[i];
	}

	cout << ans;
	return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:43:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         if (pos == dp.size()) dp.push_back(a[i]);
      |             ~~~~^~~~~~~~~~~~
glo.cpp:44:9: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   44 |         else dp[pos] = a[i]; L[i] = pos + 1;
      |         ^~~~
glo.cpp:44:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   44 |         else dp[pos] = a[i]; L[i] = pos + 1;
      |                              ^
glo.cpp:54:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if (pos == dp.size()) dp.push_back(-a[i]);
      |             ~~~~^~~~~~~~~~~~
glo.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 1760 KB Output is correct
2 Correct 50 ms 3764 KB Output is correct
3 Correct 51 ms 3796 KB Output is correct
4 Correct 49 ms 3800 KB Output is correct
5 Correct 29 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 724 KB Output is correct
2 Correct 11 ms 1096 KB Output is correct
3 Correct 12 ms 1096 KB Output is correct
4 Correct 7 ms 1260 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1136 KB Output is correct
7 Correct 9 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1108 KB Output is correct
2 Correct 21 ms 2000 KB Output is correct
3 Correct 45 ms 3840 KB Output is correct
4 Correct 30 ms 3532 KB Output is correct
5 Correct 13 ms 2008 KB Output is correct
6 Correct 23 ms 3532 KB Output is correct
7 Correct 34 ms 4156 KB Output is correct
8 Correct 18 ms 2100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 49 ms 1760 KB Output is correct
28 Correct 50 ms 3764 KB Output is correct
29 Correct 51 ms 3796 KB Output is correct
30 Correct 49 ms 3800 KB Output is correct
31 Correct 29 ms 3540 KB Output is correct
32 Correct 11 ms 724 KB Output is correct
33 Correct 11 ms 1096 KB Output is correct
34 Correct 12 ms 1096 KB Output is correct
35 Correct 7 ms 1260 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 7 ms 1136 KB Output is correct
38 Correct 9 ms 1104 KB Output is correct
39 Correct 21 ms 1108 KB Output is correct
40 Correct 21 ms 2000 KB Output is correct
41 Correct 45 ms 3840 KB Output is correct
42 Correct 30 ms 3532 KB Output is correct
43 Correct 13 ms 2008 KB Output is correct
44 Correct 23 ms 3532 KB Output is correct
45 Correct 34 ms 4156 KB Output is correct
46 Correct 18 ms 2100 KB Output is correct
47 Correct 25 ms 1964 KB Output is correct
48 Correct 23 ms 1988 KB Output is correct
49 Correct 57 ms 3820 KB Output is correct
50 Correct 27 ms 3528 KB Output is correct
51 Correct 25 ms 2876 KB Output is correct
52 Correct 28 ms 3628 KB Output is correct
53 Correct 25 ms 3604 KB Output is correct
54 Correct 34 ms 4284 KB Output is correct
55 Correct 38 ms 3756 KB Output is correct