Submission #310757

# Submission time Handle Problem Language Result Execution time Memory
310757 2020-10-07T20:03:22 Z ly20 Building Bridges (CEOI17_building) C++17
30 / 100
3000 ms 3712 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 112345;
long long dp[MAXN];
long long sp[MAXN], h[MAXN];
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%lld", &h[i]);
    }
    for(int i = 0; i < n; i++) {
            dp[i] = 1123456789012345678;
        int a;
        scanf("%d", &a);
        if(i == 0) sp[i] = a;
        else sp[i] = sp[i - 1] + a;
    }
    dp[0] = 0;
    for(int i = 1; i < n; i++) {
        for(int j = i - 1; j >= 0; j--) {
            dp[i] = min(dp[i], dp[j] + sp[i - 1] - sp[j] + (h[i] - h[j]) * (h[i] - h[j]));
        }
    }
    printf("%lld\n", dp[n - 1]);
    return 0;
}

Compilation message

building.cpp: In function 'int main()':
building.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
building.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |         scanf("%lld", &h[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
building.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3056 ms 3712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Execution timed out 3056 ms 3712 KB Time limit exceeded
7 Halted 0 ms 0 KB -