Submission #123752

# Submission time Handle Problem Language Result Execution time Memory
123752 2019-07-02T06:06:44 Z FutymyClone Building Bridges (CEOI17_building) C++14
30 / 100
3000 ms 3640 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n, h[N], w[N];
long long dp[N], f[N];

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] + w[i];

    memset(dp, 0x3f, sizeof(dp));
    dp[1] = 0;
    for (int i = 2; i <= n; i++) for (int j = 1; j < i; j++) dp[i] = min(dp[i], dp[j] + 1LL * (h[i] - h[j]) * (h[i] - h[j]) + f[i - 1] - f[j]);
    printf("%lld", dp[n]);
    return 0;
}
/*
6
3 8 7 1 6 6
0 -1 9 1 2 0
*/

Compilation message

building.cpp: In function 'int main()':
building.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
building.cpp:12:39: 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", &h[i]);
                                  ~~~~~^~~~~~~~~~~~~
building.cpp:13:39: 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", &w[i]);
                                  ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1088 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 4 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3004 ms 3640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1088 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 4 ms 1148 KB Output is correct
6 Execution timed out 3004 ms 3640 KB Time limit exceeded
7 Halted 0 ms 0 KB -