Submission #490462

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

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

vector<int> dp;

void init(int n){
  dp.resize(n , 1);
  return ;
}

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

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;
  init(n);
  vector<int> v(n);
  for(int i = 0 ; i < n ; i++){
    cin >> v[i];
  }
  fill_dp(v);
  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 0 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 0 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 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 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 0 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 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 18 ms 332 KB Output is correct
20 Correct 25 ms 336 KB Output is correct
21 Correct 17 ms 364 KB Output is correct
22 Correct 20 ms 356 KB Output is correct
23 Correct 11 ms 340 KB Output is correct
24 Correct 11 ms 332 KB Output is correct
25 Correct 10 ms 332 KB Output is correct
26 Correct 13 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 3720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2086 ms 1268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 2316 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 0 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 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 18 ms 332 KB Output is correct
20 Correct 25 ms 336 KB Output is correct
21 Correct 17 ms 364 KB Output is correct
22 Correct 20 ms 356 KB Output is correct
23 Correct 11 ms 340 KB Output is correct
24 Correct 11 ms 332 KB Output is correct
25 Correct 10 ms 332 KB Output is correct
26 Correct 13 ms 340 KB Output is correct
27 Execution timed out 2070 ms 3720 KB Time limit exceeded
28 Halted 0 ms 0 KB -