Submission #256888

#TimeUsernameProblemLanguageResultExecution timeMemory
256888BruteforcemanDischarging (NOI20_discharging)C++11
36 / 100
1088 ms14328 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const long long inf = 1e16; long long dp[maxn]; int a[maxn]; struct hull { vector <long long> M, C; bool bad(int i, int j, int k) { return (C[k] - C[j]) * (M[i] - M[k]) <= (C[k] - C[i]) * (M[j] - M[k]); } void add(long long m, long long c) { M.push_back(m); C.push_back(c); while(M.size() >= 3 && bad(M.size() - 3, M.size() - 2, M.size() - 1)) { M.erase(M.end() - 2); C.erase(C.end() - 2); } } }; int main() { int n; scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 1; i <= n; i++) { int m = a[i]; dp[i] = inf; for(int j = i - 1; j >= 0; j--) { dp[i] = min(dp[i], 1LL * m * (n - j) + dp[j]); m = max(m, a[j]); } } printf("%lld\n", dp[n]); return 0; }

Compilation message (stderr)

Discharging.cpp: In function 'int main()':
Discharging.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
Discharging.cpp:26:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
                               ~~~~~^~~~~~~~~~~~~
#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...