【UOJ #244】【UER #7】短路

http://uoj.ac/contest/35/problem/244

对其他人来说好简单的一道题,我当时却不会做TWT

注定滚粗啊

题解很好的~

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 100003;
ll in() {
ll k = 0, fh = 1; char c= getchar();
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') fh = -1;
for (; c >= '0' && c <= '9'; c = getchar())
k = k * 10 + c - 48;
return k * fh;
} int n;
ll a[N], f[N], ans, now; int main() {
scanf("%d", &n);
for (int i = 0; i <= n; ++i) a[i] = in();
f[n] = a[n];
now = a[n];
ans = a[n] * (4 * n + 1);
for (int i = n - 1; i >= 0; --i) {
f[i] = f[i + 1] + now + a[i];
if (a[i] < now) {
now = a[i];
ans = min(ans, f[i] * 2 + now * (4 * i - 1));
}
}
printf("%lld\n", ans);
return 0;
}
上一篇:tcp三次握手过程


下一篇:251. Flatten 2D Vector