Submission #490454

# Submission time Handle Problem Language Result Execution time Memory
490454 2021-11-27T15:30:37 Z fun_day Global Warming (CEOI18_glo) C++14
28 / 100
2000 ms 1864 KB
#include <bits/stdc++.h>

using namespace std;

int get_lis(vector<int> v){
  int n = (int)v.size();
  if(n == 0) return 0;
  vector<int> lis;
  for(int i = 0 ; i < n ; i++){
    int val = v[i];
    auto q = lower_bound(lis.begin(),lis.end() , val);
    if(q == lis.end()){
      lis.emplace_back(val);
    }
    else{
      *q = val;
    }
  }
  return (int)lis.size();
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n , x;
  cin >> n >> x;
  vector<int> v(n);
  for(int i = 0 ; i < n ; i++){
    cin >> v[i];
  }
  vector<int> dp(n , 1);
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < i ; j++){
      if(v[j] < v[i]){
        dp[i] = max(dp[i] , dp[j] + 1);
      }
    }
  }
  int best = 0;
  for(int i = 0 ; i < n ; i++){
    int val = v[i];
    vector<int> s;
    for(int j = i + 1 ; j < n ; j++){
      if(v[j] + x > val) s.emplace_back(v[j] + x);      
    }
    best = max(best , dp[i] + get_lis(s));
    s.clear();
    for(int j = i + 1 ; j < n ; j++){
      if(v[j] > val - x) s.emplace_back(v[j]);
    }
    best = max(best , dp[i] + get_lis(s));
  }
  cout << best << '\n';
  return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 236 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 236 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 18 ms 332 KB Output is correct
20 Correct 17 ms 372 KB Output is correct
21 Correct 17 ms 332 KB Output is correct
22 Correct 18 ms 360 KB Output is correct
23 Correct 11 ms 340 KB Output is correct
24 Correct 11 ms 340 KB Output is correct
25 Correct 11 ms 340 KB Output is correct
26 Correct 12 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2084 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2062 ms 588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 1100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 236 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 18 ms 332 KB Output is correct
20 Correct 17 ms 372 KB Output is correct
21 Correct 17 ms 332 KB Output is correct
22 Correct 18 ms 360 KB Output is correct
23 Correct 11 ms 340 KB Output is correct
24 Correct 11 ms 340 KB Output is correct
25 Correct 11 ms 340 KB Output is correct
26 Correct 12 ms 336 KB Output is correct
27 Execution timed out 2084 ms 1864 KB Time limit exceeded
28 Halted 0 ms 0 KB -