Submission #466938

#TimeUsernameProblemLanguageResultExecution timeMemory
466938AMO5Discharging (NOI20_discharging)C++17
9 / 100
1087 ms33472 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define ld long double #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define dbg if(0) #define BUG(x) dbg cerr << (#x) << " is " << (x) << endl const int mxn = (int)1e6+5; const int64_t inf = 5e18; void solve(){ int n; cin>>n; vector<int64_t>a(n); for(auto &x:a) { cin>>x; } //dp //when n is small vector<array<int64_t,2>>dp(n); for(int i=0; i<n; i++){ int64_t now = a[i], res = 0, tmp = 0; for(int len=1,j=i; j>=0; j--,len++){ now = max(now,a[j]); int64_t prev_sum = (j>0?dp[j-1][1]:(int64_t)0); int64_t sum = (j>0?dp[j-1][0]:(int64_t)0); int64_t curr = len*(now+sum)+prev_sum; dbg cerr<<i<<" "<<j<<" "<<sum<<" "<<now<<" "<<len<<" "<<prev_sum<<" "<<curr<<"\n"; if(j==i)res = curr, tmp = sum+now; else if(curr<res){ res = curr; tmp = sum+now; }else if(curr==res){ tmp = min(tmp, sum+now); } } dp[i][0]=tmp; dp[i][1]=res; dbg cerr<<dp[i][0]<<" "<<dp[i][1]<<"\n"; } cout<<dp[n-1][1]<<"\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // int t=1; cin>>t; while(t--) solve(); return 0; }
#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...