Submission #1109700

# Submission time Handle Problem Language Result Execution time Memory
1109700 2024-11-07T10:47:41 Z Trisanu_Das Nile (IOI24_nile) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

vector <ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
    int N = W.size(), Q = E.size();
    vector <tuple <int, int, int>> items;
    for (int i = 0; i < N; i++) items.push_back(make_tuple(W[i], A[i], B[i]));
    sort(items.begin(), items.end());
    for (int i = 0; i < N; ++i) {
        auto [w, a, b] = items[i];
        W[i] = w, A[i] = a, B[i] = b;
    }
    vector <ll> ans;
    for(int q = 0; q < Q; q++){
        ll d = E[q];
        vector<ll> dp(N + 1, INT_MAX);
        for(int i = 0; i < N; ++i){
            if(i == 0) dp[i] = A[i];
            else if(i == 1){
                if(W[i] - W[i - 1] <= d) dp[i] = B[i] + B[i - 1];
                else dp[i] = dp[i - 1] + A[i];
            }
            else{
                dp[i] = dp[i - 1] + A[i];
                if(W[i] - W[i - 1] <= d) dp[i] = min(dp[i], (ll)(B[i] + B[i - 1] + dp[i - 2]));
                if(W[i] - W[i - 2] <= d){
                    if(i >= 3) dp[i] = min(dp[i], (ll)(B[i] + A[i - 1] + B[i - 2] + dp[i - 3]));
                    else dp[i] = min(dp[i], (ll)(B[i] + A[i - 1] + B[i - 2]));
                }
            }
        }
        ans.push_back(dp[N - 1]);
    }
    return ans;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, q; cin >> n >> q;
    vector<int> a(n), b(n), w(n), e(q);
    for(int i = 0; i < n; i++) cin >> w[i];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < q; i++) cin >> e[i];
    vector<ll> ans = calculate_costs(w, a, b, e);
    for(ll res : ans) cout << res << '\n';
}

Compilation message

/usr/bin/ld: /tmp/ccLAdxC2.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccuR4gM1.o:nile.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status