제출 #785339

#제출 시각아이디문제언어결과실행 시간메모리
785339makanhuliaGlobal Warming (CEOI18_glo)C++17
0 / 100
2081 ms5068 KiB
# include <bits/stdc++.h> # define int long long # define vi vector<int> # define pb push_back # define pii pair<int, int> # define fi first # define se second # define endl '\n' # define jess ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; int n, x, a[200005], b[200005], memo[55][55]; int dp(int idx, int last) { if(idx>n) return 0; if(memo[idx][last]!=-1) return memo[idx][last]; int best=dp(idx+1, last); if(b[idx]>b[last]) { best=max(best, dp(idx+1, idx)+1); } return memo[idx][last]=best; } void solve() { cin >> n >> x; for(int i=1; i<=n; i++) { cin >> a[i]; } int last=a[1], start=1, end=1; vector<pii> v; for(int i=2; i<=n; i++) { if(a[i]>last) { last=a[i]; end++; } else { v.pb({start, end}); start=i; last=a[i]; end=i; } } v.pb({start, n}); int ans=0; for(int j=1; j<=n; j++) b[j]=a[j]; for(pii i : v) { for(int s=(-1)*x; s<=x; s++) { memset(memo, -1, sizeof(memo)); for(int j=i.fi; j<=i.se; j++) { b[j]+=s; } b[0]=0; // cout << "plus " << s << endl; // cout << "dp " << dp(1, 0) << endl; ans=max(ans, dp(1, 0)); for(int j=i.fi; j<=i.se; j++) b[j]-=s; } } cout << ans << endl; } signed main() { jess; solve(); }
#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...