Submission #982609

#TimeUsernameProblemLanguageResultExecution timeMemory
982609SmuggingSpunGlobal Warming (CEOI18_glo)C++14
42 / 100
51 ms4628 KiB
#include<bits/stdc++.h> #define taskname "glo" using namespace std; typedef long long ll; template<class T>void maximize(T& a, T b){ if(a < b){ a = b; } } const int lim = 2e5 + 5; const int INF = 2e9 + 1; int n, X, a[lim]; namespace sub12{ void solve(){ int ans = 0; for(int i = 1; i <= n; i++){ for(int j = i; j <= n; j++){ for(int d = -X; d <= X; d++){ vector<int>t(n + 1), f(n + 1, INF); for(int k = 1; k <= n; k++){ t[k] = a[k]; } for(int k = i; k <= j; k++){ t[k] += d; } f[0] = -INF; for(int k = 1; k <= n; k++){ int low = 0, high = n - 1, p; while(low <= high){ int mid = (low + high) >> 1; if(f[mid] < t[k]){ low = (p = mid) + 1; } else{ high = mid - 1; } } f[++p] = t[k]; maximize(ans, p); } } } } cout << ans; } } namespace sub4{ void solve(){ vector<int>f(n + 1, INF); f[0] = -INF; int ans = 0; for(int k = 1; k <= n; k++){ int low = 0, high = n - 1, p; while(low <= high){ int mid = (low + high) >> 1; if(f[mid] < a[k]){ low = (p = mid) + 1; } else{ high = mid - 1; } } f[++p] = a[k]; maximize(ans, p); } cout << ans; } } namespace sub3567{ int f[lim], p[lim]; void solve(){ fill(p, p + lim, INF); p[0] = -INF; for(int i = 1; i <= n; i++){ int low = 0, high = n - 1, P; while(low <= high){ int mid = (low + high) >> 1; if(p[mid] < a[i]){ low = (P = mid) + 1; } else{ high = mid - 1; } } p[++P] = a[i]; f[i] = max(f[i - 1], P); } int ans = f[n]; fill(p, p + lim, -INF); p[0] = INF; for(int i = n, pre = 0; i > 0; i--){ int low = 0, high = n - 1, P; a[i] += X; while(low <= high){ int mid = (low + high) >> 1; if(p[mid] > a[i]){ low = (P = mid) + 1; } else{ high = mid - 1; } } p[++P] = a[i]; maximize(ans, (pre = max(pre, P)) + f[i - 1]); } cout << ans; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n >> X; for(int i = 1; i <= n; i++){ cin >> a[i]; } if(n <= 50){ sub12::solve(); } else if(X == 0){ sub4::solve(); } else{ sub3567::solve(); } }

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:112:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp: In function 'void sub3567::solve()':
glo.cpp:103:6: warning: 'P' may be used uninitialized in this function [-Wmaybe-uninitialized]
  103 |    p[++P] = a[i];
      |      ^~~
glo.cpp:85:6: warning: 'P' may be used uninitialized in this function [-Wmaybe-uninitialized]
   85 |    p[++P] = a[i];
      |      ^~~
glo.cpp: In function 'void sub12::solve()':
glo.cpp:38:14: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |       f[++p] = t[k];
glo.cpp: In function 'void sub4::solve()':
glo.cpp:63:11: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |    f[++p] = a[k];
#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...