Submission #1099779

# Submission time Handle Problem Language Result Execution time Memory
1099779 2024-10-12T05:15:43 Z model_code Nile (IOI24_nile) C++17
67 / 100
2000 ms 13088 KB
// time_limit/hazem_dp_qn.cpp

#include "bits/stdc++.h"
#include "nile.h"
using namespace std;

const long long INF = 1e14;

vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
    int n = W.size();
    int q = E.size();

    vector<int> ordW(n);
    iota(ordW.begin() ,ordW.end() ,0);
    sort(ordW.begin() ,ordW.end() ,[&](int i ,int j){
        return W[i] < W[j];
    });
    vector<int> w(n), a(n), b(n);
    for(int i = 0; i < n; i++){
        int j = ordW[i];
        w[i] = W[j];
        a[i] = A[j];
        b[i] = B[j];
    }

    auto solve = [&](int d){
        vector<vector<long long>> dp(n+1, vector<long long>(4, INF));
        dp[n][0] = 0;
        for(int i = n - 1; i >= 0; i--){
            dp[i][0] = min(a[i] + dp[i+1][0], b[i] + dp[i+1][1]);
            for(int j = i - 1; j >= 0 && i - j <= 2 && w[i] - w[j] <= d; j--)
                dp[i][i-j] = min(a[i] + dp[i+1][i+1-j], b[i] + dp[i+1][0]);
        }
        return dp[0][0];
    };

    vector<long long> R(q);
    for(int i = 0; i < q; i++)
        R[i] = solve(E[i]);
    return R;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 11356 KB Output is correct
2 Correct 42 ms 11356 KB Output is correct
3 Correct 46 ms 11368 KB Output is correct
4 Correct 47 ms 11352 KB Output is correct
5 Correct 48 ms 11348 KB Output is correct
6 Correct 52 ms 11352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 11348 KB Output is correct
2 Correct 50 ms 11344 KB Output is correct
3 Correct 49 ms 11348 KB Output is correct
4 Correct 46 ms 11356 KB Output is correct
5 Correct 57 ms 11344 KB Output is correct
6 Correct 50 ms 11332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 43 ms 11356 KB Output is correct
8 Correct 42 ms 11356 KB Output is correct
9 Correct 46 ms 11368 KB Output is correct
10 Correct 47 ms 11352 KB Output is correct
11 Correct 48 ms 11348 KB Output is correct
12 Correct 52 ms 11352 KB Output is correct
13 Correct 49 ms 11348 KB Output is correct
14 Correct 50 ms 11344 KB Output is correct
15 Correct 49 ms 11348 KB Output is correct
16 Correct 46 ms 11356 KB Output is correct
17 Correct 57 ms 11344 KB Output is correct
18 Correct 50 ms 11332 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 55 ms 11348 KB Output is correct
26 Correct 57 ms 11344 KB Output is correct
27 Correct 57 ms 11356 KB Output is correct
28 Correct 56 ms 11372 KB Output is correct
29 Correct 59 ms 11348 KB Output is correct
30 Correct 66 ms 11344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 11348 KB Output is correct
2 Correct 50 ms 11344 KB Output is correct
3 Correct 49 ms 11348 KB Output is correct
4 Correct 46 ms 11356 KB Output is correct
5 Correct 57 ms 11344 KB Output is correct
6 Correct 50 ms 11332 KB Output is correct
7 Execution timed out 2053 ms 13088 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 43 ms 11356 KB Output is correct
9 Correct 42 ms 11356 KB Output is correct
10 Correct 46 ms 11368 KB Output is correct
11 Correct 47 ms 11352 KB Output is correct
12 Correct 48 ms 11348 KB Output is correct
13 Correct 52 ms 11352 KB Output is correct
14 Correct 49 ms 11348 KB Output is correct
15 Correct 50 ms 11344 KB Output is correct
16 Correct 49 ms 11348 KB Output is correct
17 Correct 46 ms 11356 KB Output is correct
18 Correct 57 ms 11344 KB Output is correct
19 Correct 50 ms 11332 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 55 ms 11348 KB Output is correct
27 Correct 57 ms 11344 KB Output is correct
28 Correct 57 ms 11356 KB Output is correct
29 Correct 56 ms 11372 KB Output is correct
30 Correct 59 ms 11348 KB Output is correct
31 Correct 66 ms 11344 KB Output is correct
32 Execution timed out 2053 ms 13088 KB Time limit exceeded
33 Halted 0 ms 0 KB -