Submission #477277

#TimeUsernameProblemLanguageResultExecution timeMemory
477277Shogun3103Global Warming (CEOI18_glo)C++17
100 / 100
68 ms10056 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define FOR(i,a,b) for(__typeof(b) i=a; i<=b; i++) #define FOD(i,a,b) for(__typeof(b) i=b; i>=a; i--) #define EACH(u, v) for(auto& u : v) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define pb push_back #define ii pair<int,int> #define iii pair<int,ii> #define f first #define s second #define ed "\n" #define sp " " #define vi vector<int> #define vii vector<ii> #define vl vector<ll> #define NO cout << "NO" << ed; #define YES cout << "YES" << ed; #define no cout << "no" << ed; #define yes cout << "yes" << ed; void setIO(string fileName = ""){ if(fileName.length()){ freopen((fileName+".in").c_str(), "r", stdin); freopen((fileName+".out").c_str(), "w", stdout); } } int lnds(vl a) { vi calc; for(int q : a) { int pos = upper_bound(all(calc), q) - calc.begin(); if(pos == sz(calc)) calc.pb(q); else calc[pos] = q; } return sz(calc); } const int oo1 = 1e9 + 7; const int oo2 = 1e9 + 9; const int d4x[] = {0, 0, 1, -1}; const int d4y[] = {1, -1, 0, 0}; const int d8x[] = {-1, 0, 1, -1, 1, -1, 0, 1}; const int d8y[] = {1, 1, 1, 0, 0, -1, -1, -1}; const int N = 2e5 + 10; const int M = 5e3 + 10; vi adj[N]; int n, m; int a[N], x, pre[N]; void solve() { cin >> n >> x; FOR(i, 1, n) cin >> a[i]; //left int ans = 0; vi dp(n, oo1); FOR(i, 1, n) { int j = lower_bound(all(dp), a[i]) - dp.begin(); dp[j] = a[i]; pre[i] = j + 1; ans = max(ans, pre[i]); } //right dp = vi(n, oo1); FOD(i, 1, n) { int j = lower_bound(all(dp), -a[i] + x) - dp.begin(); ans = max(ans, pre[i] + j); int jj = lower_bound(all(dp), -a[i]) - dp.begin(); dp[jj] = -a[i]; } cout << ans; } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); setIO(""); int t; t = 1; //int t; cin >> t; FOR(i, 1, t) solve(); return 0; }

Compilation message (stderr)

glo.cpp: In function 'void setIO(std::string)':
glo.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((fileName+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen((fileName+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...