Submission #1110909

# Submission time Handle Problem Language Result Execution time Memory
1110909 2024-11-11T02:12:30 Z luvna Building Bridges (CEOI17_building) C++14
30 / 100
3000 ms 2640 KB
#include<bits/stdc++.h>

#define all(v) v.begin(), v.end()
#define endl "\n"
#define sz(v) (int)(v).size()
#define int long long

using namespace std;

typedef long long ll;

const int N = 1e5 + 15;
const ll INF = 1e18;

int n;
int h[N];
ll dp[N];
int w[N];

ll sum(int l, int r){
    if(l > r) return 0;
    ll res = 0;
    for(int i = l; i <= r; i++) res += w[i];
    return res;
}

void solve(){
    cin >> n;

    for(int i = 1; i <= n; i++) cin >> h[i];
    for(int i = 1; i <= n; i++) cin >> w[i];

    for(int i = 2; i <= n; i++){
        dp[i] = INF;
        for(int j = i-1; j >= 1; j--){
            dp[i] = min(dp[i], 1LL*(h[i]-h[j])*(h[i]-h[j]) + sum(j+1,i-1) + dp[j]);
        }
    }

    cout << dp[n];
}

signed main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);

    #define task "task"

    if(fopen(task".INP", "r")){
        freopen(task".INP", "r", stdin);
        freopen(task".ANS", "w", stdout);
    }

    int t; t = 1; //cin >> t;
    while(t--) solve();
}

Compilation message

building.cpp: In function 'int main()':
building.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(task".ANS", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 76 ms 2384 KB Output is correct
5 Correct 70 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3035 ms 2640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 76 ms 2384 KB Output is correct
5 Correct 70 ms 2384 KB Output is correct
6 Execution timed out 3035 ms 2640 KB Time limit exceeded
7 Halted 0 ms 0 KB -