답안 #367223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367223 2021-02-16T15:35:15 Z leu_naut Global Warming (CEOI18_glo) C++11
100 / 100
64 ms 4332 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define FOR(i,a,b) for (int i = a; i <= b; ++i)
#define FORd(i,a,b) for (int i = a; i >= b; --i)
#define FastRead ios_base::sync_with_stdio(0); cin.tie(nullptr);
#define II pair <ll,ll>
 
const int N = 2e5;
const ll oo = 1e18;
const int maxN = 2e9;
const int MOD = 1e9 + 7;
 
ll a[N + 10], dp[N + 10];
 
int main()	
{	
/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif //ONLINE_JUDGE */
	FastRead	
	int n,x;
	ll k = 0;
	cin >> n >> x;
	for (int i = 0; i < n; ++i) cin >> a[i];
	vector <ll> lis;
	//Longest increasing subsequence ending at pos i
	for (int i = 0; i < n; ++i)	{
		int pos = lower_bound(lis.begin(),lis.end(),a[i]) - lis.begin();
		if (pos == lis.size()) lis.push_back(a[i]);
		else lis[pos] = a[i];
		dp[i] = pos + 1;
		k = max(k, dp[i]);
	}
	lis.clear();
	//Longest increasing subsequence starting at pos i and decrease all [1,i] by x
	//= Longest increase minus subsequence ending at pos i with reverse array and plus x.
	for (int i = n - 1; i >= 0; --i) {
		ll p = lower_bound(lis.begin(),lis.end(), -a[i] + x) - lis.begin();
		int pos = lower_bound(lis.begin(),lis.end(),-a[i]) - lis.begin();
		if (pos == lis.size()) lis.push_back(-a[i]);
		else lis[pos] = -a[i];
		k = max(k,dp[i] + p);
	}
	cout << k;
}	

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:34:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   if (pos == lis.size()) lis.push_back(a[i]);
      |       ~~~~^~~~~~~~~~~~~
glo.cpp:45:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   if (pos == lis.size()) lis.push_back(-a[i]);
      |       ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 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 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 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 0 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 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 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 0 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 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 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 508 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 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 3564 KB Output is correct
2 Correct 60 ms 3436 KB Output is correct
3 Correct 61 ms 3436 KB Output is correct
4 Correct 63 ms 3436 KB Output is correct
5 Correct 33 ms 4328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1152 KB Output is correct
2 Correct 15 ms 1132 KB Output is correct
3 Correct 14 ms 1132 KB Output is correct
4 Correct 8 ms 1392 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 9 ms 1392 KB Output is correct
7 Correct 12 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1900 KB Output is correct
2 Correct 25 ms 1900 KB Output is correct
3 Correct 51 ms 3436 KB Output is correct
4 Correct 32 ms 4328 KB Output is correct
5 Correct 16 ms 2412 KB Output is correct
6 Correct 27 ms 4200 KB Output is correct
7 Correct 33 ms 4204 KB Output is correct
8 Correct 21 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 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 0 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 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 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 508 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 512 KB Output is correct
27 Correct 64 ms 3564 KB Output is correct
28 Correct 60 ms 3436 KB Output is correct
29 Correct 61 ms 3436 KB Output is correct
30 Correct 63 ms 3436 KB Output is correct
31 Correct 33 ms 4328 KB Output is correct
32 Correct 14 ms 1152 KB Output is correct
33 Correct 15 ms 1132 KB Output is correct
34 Correct 14 ms 1132 KB Output is correct
35 Correct 8 ms 1392 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 9 ms 1392 KB Output is correct
38 Correct 12 ms 1132 KB Output is correct
39 Correct 25 ms 1900 KB Output is correct
40 Correct 25 ms 1900 KB Output is correct
41 Correct 51 ms 3436 KB Output is correct
42 Correct 32 ms 4328 KB Output is correct
43 Correct 16 ms 2412 KB Output is correct
44 Correct 27 ms 4200 KB Output is correct
45 Correct 33 ms 4204 KB Output is correct
46 Correct 21 ms 1884 KB Output is correct
47 Correct 34 ms 1900 KB Output is correct
48 Correct 29 ms 1900 KB Output is correct
49 Correct 64 ms 3436 KB Output is correct
50 Correct 32 ms 4328 KB Output is correct
51 Correct 27 ms 3564 KB Output is correct
52 Correct 40 ms 4328 KB Output is correct
53 Correct 31 ms 4328 KB Output is correct
54 Correct 35 ms 4332 KB Output is correct
55 Correct 48 ms 3436 KB Output is correct