Submission #1036249

# Submission time Handle Problem Language Result Execution time Memory
1036249 2024-07-27T07:03:59 Z coolsentenceidontremember Global Warming (CEOI18_glo) C++17
100 / 100
39 ms 5344 KB
#include<bits/stdc++.h>

#pragma GCC optimize("O3", "unroll-loops")


#define ll long long
#define ld long double
#define ff first
#define ss second
#define db double
#define time_begin() auto begin = chrono::high_resolution_clock::now()
#define time_end() auto end = chrono::high_resolution_clock::now(); auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end-begin); auto sec = elapsed.count() * 1e-9; cerr << "\n\nExecution time: " << sec << " seconds";
#define check_time() cerr << "\nStatus : "; if (sec>1) cerr << "Time Limit Exceeded 1!!!1!111"; else cerr << "You good brother"

using namespace std;

void setIO(string s = ""){
 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 cout.tie(nullptr);
 if (!s.empty()){
	freopen((s+".in").c_str(), "r", stdin);
	freopen((s+".out").c_str(), "w", stdout);
	}
}





int main(){
   setIO();
   int n, x;
   cin >> n >> x;
   int a[n];
   for (int &i : a) cin >> i;
   int l[n], r[n];
   vector<int> lis;
   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];
   	 l[i] = pos+1;
   	}
    lis.clear();
    for (int i = n-1; i >= 0; i--){
    	int pos = lower_bound(lis.begin(), lis.end(), -a[i] + x) - lis.begin();
    	r[i] = pos;
    	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];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) ans = max(ans, l[i] + r[i]);
	cout << ans;
}


Compilation message

glo.cpp: In function 'int main()':
glo.cpp:41:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |      if (pos == lis.size()) lis.push_back(a[i]);
      |          ~~~~^~~~~~~~~~~~~
glo.cpp:50:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |      if (pos == lis.size()) lis.push_back(-a[i]);
      |          ~~~~^~~~~~~~~~~~~
glo.cpp: In function 'void setIO(std::string)':
glo.cpp:22:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  freopen((s+".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:23:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  freopen((s+".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 4696 KB Output is correct
2 Correct 36 ms 4700 KB Output is correct
3 Correct 39 ms 4672 KB Output is correct
4 Correct 36 ms 4696 KB Output is correct
5 Correct 21 ms 4572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1372 KB Output is correct
2 Correct 8 ms 1388 KB Output is correct
3 Correct 10 ms 1524 KB Output is correct
4 Correct 5 ms 1372 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 1368 KB Output is correct
7 Correct 7 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2396 KB Output is correct
2 Correct 17 ms 2492 KB Output is correct
3 Correct 33 ms 4696 KB Output is correct
4 Correct 21 ms 4576 KB Output is correct
5 Correct 10 ms 2524 KB Output is correct
6 Correct 16 ms 4512 KB Output is correct
7 Correct 21 ms 5088 KB Output is correct
8 Correct 14 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 36 ms 4696 KB Output is correct
28 Correct 36 ms 4700 KB Output is correct
29 Correct 39 ms 4672 KB Output is correct
30 Correct 36 ms 4696 KB Output is correct
31 Correct 21 ms 4572 KB Output is correct
32 Correct 9 ms 1372 KB Output is correct
33 Correct 8 ms 1388 KB Output is correct
34 Correct 10 ms 1524 KB Output is correct
35 Correct 5 ms 1372 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 5 ms 1368 KB Output is correct
38 Correct 7 ms 1536 KB Output is correct
39 Correct 16 ms 2396 KB Output is correct
40 Correct 17 ms 2492 KB Output is correct
41 Correct 33 ms 4696 KB Output is correct
42 Correct 21 ms 4576 KB Output is correct
43 Correct 10 ms 2524 KB Output is correct
44 Correct 16 ms 4512 KB Output is correct
45 Correct 21 ms 5088 KB Output is correct
46 Correct 14 ms 2396 KB Output is correct
47 Correct 17 ms 2392 KB Output is correct
48 Correct 17 ms 2392 KB Output is correct
49 Correct 35 ms 4696 KB Output is correct
50 Correct 19 ms 4576 KB Output is correct
51 Correct 21 ms 3852 KB Output is correct
52 Correct 19 ms 4572 KB Output is correct
53 Correct 17 ms 4572 KB Output is correct
54 Correct 21 ms 5344 KB Output is correct
55 Correct 30 ms 4548 KB Output is correct