Submission #117496

# Submission time Handle Problem Language Result Execution time Memory
117496 2019-06-16T09:16:40 Z zubec Boxes with souvenirs (IOI15_boxes) C++14
50 / 100
49 ms 12024 KB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;

long long dp[1000100];

long long delivery(int N, int K, int L, int p[]) {

    int mid = L/2;
    int lstPos = -1;
    for (int i = 1; i <= N; i++){
        dp[i] = 1e18;
        bool bb = 0;
        int pos = p[i-1];
        if (lstPos == -1 && pos >= L-mid)
            lstPos = i;
        int pos2 = p[max(0, i-K)];
        if ((pos2 <= mid && pos <= mid) || (pos2 >= mid && pos >= mid) ){
            dp[i] = min(dp[i], dp[max(0, i-K)] + max(min(pos2, L-pos2), min(pos, L-pos))*2 );
        } else {
            dp[i] = min(dp[i], dp[max(0, i-K)] + L);
            dp[i] = min(dp[i], dp[lstPos-1] + max(min(p[lstPos-1], L-p[lstPos-1]), min(pos, L-pos))*2 );
        }
        //cout << i << ' ' << dp[i] << endl;
        /*for (int j = 1; j <= K; j++){
            if (i-j < 0)
                break;
            int pos2 = p[i-j];
            if (mid != pos2 && mid != pos && (mid-pos2)/abs(mid-pos2) != (mid-pos)/abs(mid-pos) ){
                bb = 1;
            }
            if (bb){
                dp[i] = min(dp[i], dp[i-j] + L);
            } else {
                dp[i] = min(dp[i], dp[i-j] + max(min(pos2, L-pos2), min(pos, L-pos))*2);
            }
        }*/
    }
    long long ans = dp[N];
    lstPos = -1;
    dp[N+1] = 0;
    for (int i = N; i >= 1; i--){
        dp[i] = 1e18;
        bool bb = 0;
        int pos = p[i-1];
        if (lstPos == -1 && pos <= mid)
            lstPos = i;
        int pos2 = p[min(N, i+K-1)-1];
        if ((pos2 <= mid && pos <= mid) || (pos2 >= mid && pos >= mid) ){
            dp[i] = min(dp[i], dp[min(N+1, i+K)] + max(min(pos2, L-pos2), min(pos, L-pos))*2 );
        } else {
            dp[i] = min(dp[i], dp[min(N+1, i+K)] + L);
            dp[i] = min(dp[i], dp[lstPos+1] + max(min(p[lstPos-1], L-p[lstPos-1]), min(pos, L-pos))*2 );
        }
        /*for (int j = 1; j <= K; j++){
            if (i-j < 0)
                break;
            int pos2 = p[i-j];
            if (mid != pos2 && mid != pos && (mid-pos2)/abs(mid-pos2) != (mid-pos)/abs(mid-pos) ){
                bb = 1;
            }
            if (bb){
                dp[i] = min(dp[i], dp[i-j] + L);
            } else {
                dp[i] = min(dp[i], dp[i-j] + max(min(pos2, L-pos2), min(pos, L-pos))*2);
            }
        }*/
    }
    ans = min(ans, dp[1]);
    return ans;

}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:13:14: warning: unused variable 'bb' [-Wunused-variable]
         bool bb = 0;
              ^~
boxes.cpp:44:14: warning: unused variable 'bb' [-Wunused-variable]
         bool bb = 0;
              ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 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 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 284 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 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 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 284 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 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 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 284 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Incorrect 49 ms 12024 KB Output isn't correct
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 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 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 284 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Incorrect 49 ms 12024 KB Output isn't correct
34 Halted 0 ms 0 KB -