Submission #490462

#TimeUsernameProblemLanguageResultExecution timeMemory
490462fun_dayGlobal Warming (CEOI18_glo)C++14
28 / 100
2086 ms3720 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...