Submission #1106047

# Submission time Handle Problem Language Result Execution time Memory
1106047 2024-10-29T03:30:29 Z jadai007 Nile (IOI24_nile) C++17
67 / 100
2000 ms 7720 KB
#include <bits/stdc++.h>
#include "nile.h"
#define ll long long

using namespace std;

vector<long long> 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>> Ws;
    vector<ll> ans;
    for(int i = 0; i < N; ++i) Ws.emplace_back(W[i], A[i], B[i]);
    sort(Ws.begin(), Ws.end());
    for(int i = 0; i < N; ++i) W[i] = get<0>(Ws[i]), A[i] = get<1>(Ws[i]), B[i] = get<2>(Ws[i]);
    for(int i = 0; i < q; ++i){
        int d = E[i];
        vector<ll> dp(N+1, LLONG_MAX);
        for(int i = 0; i < N; ++i){
            if(i == 0) dp[i] = (ll)A[i];
            else if(i == 1){
                if(W[i] - W[i - 1] <= d) dp[i] = (ll)B[i] + (ll)B[i - 1];
                else dp[i] = dp[i - 1] + (ll)A[i];
            }
            else{
                dp[i] = dp[i - 1] + (ll)A[i];
                if(W[i] - W[i - 1] <= d) dp[i] = min(dp[i], (ll)((ll)B[i] + (ll)B[i - 1] + dp[i - 2]));
                if(W[i] - W[i - 2] <= d){
                    if(i >= 3) dp[i] = min(dp[i], (ll)((ll)B[i] + (ll)A[i - 1] + (ll)B[i - 2] + dp[i - 3]));
                    else dp[i] = min(dp[i], (ll)((ll)B[i] + (ll)A[i - 1] + (ll)B[i - 2]));
                }
            }
        }
        ans.push_back(dp[N - 1]);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 4704 KB Output is correct
2 Correct 29 ms 7368 KB Output is correct
3 Correct 29 ms 7104 KB Output is correct
4 Correct 28 ms 7104 KB Output is correct
5 Correct 28 ms 7368 KB Output is correct
6 Correct 29 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 5628 KB Output is correct
2 Correct 31 ms 6088 KB Output is correct
3 Correct 31 ms 6088 KB Output is correct
4 Correct 34 ms 6088 KB Output is correct
5 Correct 30 ms 6088 KB Output is correct
6 Correct 28 ms 6080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 396 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 524 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 396 KB Output is correct
7 Correct 25 ms 4704 KB Output is correct
8 Correct 29 ms 7368 KB Output is correct
9 Correct 29 ms 7104 KB Output is correct
10 Correct 28 ms 7104 KB Output is correct
11 Correct 28 ms 7368 KB Output is correct
12 Correct 29 ms 7368 KB Output is correct
13 Correct 30 ms 5628 KB Output is correct
14 Correct 31 ms 6088 KB Output is correct
15 Correct 31 ms 6088 KB Output is correct
16 Correct 34 ms 6088 KB Output is correct
17 Correct 30 ms 6088 KB Output is correct
18 Correct 28 ms 6080 KB Output is correct
19 Correct 2 ms 336 KB Output is correct
20 Correct 2 ms 524 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 524 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 760 KB Output is correct
25 Correct 37 ms 7324 KB Output is correct
26 Correct 46 ms 7720 KB Output is correct
27 Correct 37 ms 7616 KB Output is correct
28 Correct 48 ms 7616 KB Output is correct
29 Correct 36 ms 7624 KB Output is correct
30 Correct 37 ms 7616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 5628 KB Output is correct
2 Correct 31 ms 6088 KB Output is correct
3 Correct 31 ms 6088 KB Output is correct
4 Correct 34 ms 6088 KB Output is correct
5 Correct 30 ms 6088 KB Output is correct
6 Correct 28 ms 6080 KB Output is correct
7 Execution timed out 2059 ms 7112 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 452 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 25 ms 4704 KB Output is correct
9 Correct 29 ms 7368 KB Output is correct
10 Correct 29 ms 7104 KB Output is correct
11 Correct 28 ms 7104 KB Output is correct
12 Correct 28 ms 7368 KB Output is correct
13 Correct 29 ms 7368 KB Output is correct
14 Correct 30 ms 5628 KB Output is correct
15 Correct 31 ms 6088 KB Output is correct
16 Correct 31 ms 6088 KB Output is correct
17 Correct 34 ms 6088 KB Output is correct
18 Correct 30 ms 6088 KB Output is correct
19 Correct 28 ms 6080 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 524 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 524 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 2 ms 760 KB Output is correct
26 Correct 37 ms 7324 KB Output is correct
27 Correct 46 ms 7720 KB Output is correct
28 Correct 37 ms 7616 KB Output is correct
29 Correct 48 ms 7616 KB Output is correct
30 Correct 36 ms 7624 KB Output is correct
31 Correct 37 ms 7616 KB Output is correct
32 Execution timed out 2059 ms 7112 KB Time limit exceeded
33 Halted 0 ms 0 KB -