Advertisement
pb_jiang

CF1272D WA

Apr 25th, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. // Problem: D. Remove One Element
  2. // Contest: Codeforces - Codeforces Round 605 (Div. 3)
  3. // URL: https://codeforces.com/contest/1272/problem/D
  4. // Memory Limit: 256 MB
  5. // Time Limit: 2000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  13. template <typename... Args> void logger(string vars, Args &&... values)
  14. {
  15.     cerr << vars << " = ";
  16.     string delim = "";
  17.     (..., (cerr << delim << values, delim = ", "));
  18.     cerr << endl;
  19. }
  20.  
  21. template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
  22. template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
  23. template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
  24. template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
  25.  
  26. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  27.  
  28. using ll = long long;
  29. using pii = pair<int, int>;
  30. using vl = vector<ll>;
  31. using vi = vector<int>;
  32.  
  33. int main(int argc, char **argv)
  34. {
  35.     int n;
  36.     cin >> n;
  37.     vi a(n);
  38.     for (auto &x : a)
  39.         cin >> x;
  40.     using a2i = array<int, 2>;
  41.     vector<a2i> dp(n);
  42.  
  43.     int ans = 1;
  44.     dp[0][0] = 1, dp[0][1] = 0;
  45.     // dp[i][0] keep all, dp[i][1] skip 1 element
  46.     for (int i = 1; i < n; ++i) {
  47.         if (a[i] > a[i - 1]) {
  48.             dp[i][0] = dp[i - 1][0] + 1;
  49.             dp[i][1] = max(dp[i - 1][0], dp[i - 1][1] + 1);
  50.         } else {
  51.             dp[i][0] = 1;
  52.             dp[i][1] = dp[i - 1][0];
  53.             if (i >= 2 && a[i] > a[i - 2])
  54.                 dp[i][1] = max(dp[i][1], dp[i - 2][0] + 1);
  55.         }
  56.         ans = max({ans, dp[i][0], dp[i][1]});
  57.     }
  58.     cout << ans << endl;
  59.     return 0;
  60. };
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement