제출 #785434

#제출 시각아이디문제언어결과실행 시간메모리
785434devariaotaGlobal Warming (CEOI18_glo)C++17
15 / 100
2072 ms22812 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[1005][1005]; void mem_set() { for(int i=0; i<=n+1; i++) { for(int j=0; j<=n+1; j++) memo[i][j]=-1; } } 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 ans=0; for(int j=1; j<=n; j++) b[j]=a[j]; for(int l=1; l<=n; l++) { for(int r=l; r<=n; r++) { mem_set(); for(int j=l; j<=r; j++) { b[j]+=((-1)*x); } b[0]=0; // cout << "plus " << s << endl; // cout << "dp " << dp(1, 0) << endl; ans=max(ans, dp(1, 0)); for(int j=l; j<=r; j++) b[j]-=((-1)*x); mem_set(); for(int j=l; j<=r; j++) { b[j]+=(x); } b[0]=0; // cout << "plus " << s << endl; // cout << "dp " << dp(1, 0) << endl; ans=max(ans, dp(1, 0)); for(int j=l; j<=r; j++) b[j]-=(x); } } 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...