Submission #1008986

# Submission time Handle Problem Language Result Execution time Memory
1008986 2024-06-27T07:28:22 Z jer033 Boxes with souvenirs (IOI15_boxes) C++17
100 / 100
483 ms 374028 KB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1'000'111'000'111'000'111;

long long delivery(int N, int K, int L, int p[]) {
    ll slices = L;
    vector<ll> locs;
    for (int i=0; i<N; i++)
    {
        if (p[i]!=0)
            locs.push_back(p[i]);
    }
    N = locs.size();//update N, I don't care how many teams are sitting in section 0
    vector<ll> forwards(N, 0);
    for (int i=0; i<N; i++)
    {
        if (i<K)
            forwards[i] = 2*locs[i];
        else
            forwards[i] = forwards[i-K]+(2*locs[i]);
    }
    vector<ll> backwards(N, 0);
    for (int i=N-1; i>=0; i--)
    {
        if (i>=(N-K))
            backwards[i] = 2*(L-locs[i]);
        else
            backwards[i] = backwards[i+K]+(2*(L-locs[i]));
    }
    ll bestcost = INF;
    for (int i=-1; i<N; i++)
        for (ll circles=0; circles<=2; circles++)
        {
            int j = i+1+(K*circles);
            ll cost = 0;
            if (i!=-1)
                cost+=forwards[i];
            if (j<N)
                cost+=backwards[j];
            cost+=(slices*circles);
            bestcost = min(bestcost, cost);
        }
    return bestcost;
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:15:18: warning: conversion from 'std::vector<long long int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   15 |     N = locs.size();//update N, I don't care how many teams are sitting in section 0
      |         ~~~~~~~~~^~
boxes.cpp:36:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   36 |             int j = i+1+(K*circles);
      |                     ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 43 ms 27944 KB Output is correct
34 Correct 20 ms 27080 KB Output is correct
35 Correct 22 ms 29104 KB Output is correct
36 Correct 48 ms 37676 KB Output is correct
37 Correct 47 ms 37560 KB Output is correct
38 Correct 47 ms 37660 KB Output is correct
39 Correct 41 ms 36024 KB Output is correct
40 Correct 27 ms 31416 KB Output is correct
41 Correct 47 ms 37576 KB Output is correct
42 Correct 26 ms 31684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 43 ms 27944 KB Output is correct
34 Correct 20 ms 27080 KB Output is correct
35 Correct 22 ms 29104 KB Output is correct
36 Correct 48 ms 37676 KB Output is correct
37 Correct 47 ms 37560 KB Output is correct
38 Correct 47 ms 37660 KB Output is correct
39 Correct 41 ms 36024 KB Output is correct
40 Correct 27 ms 31416 KB Output is correct
41 Correct 47 ms 37576 KB Output is correct
42 Correct 26 ms 31684 KB Output is correct
43 Correct 467 ms 371204 KB Output is correct
44 Correct 148 ms 247752 KB Output is correct
45 Correct 210 ms 297796 KB Output is correct
46 Correct 454 ms 373868 KB Output is correct
47 Correct 483 ms 372120 KB Output is correct
48 Correct 459 ms 373752 KB Output is correct
49 Correct 403 ms 357696 KB Output is correct
50 Correct 234 ms 310764 KB Output is correct
51 Correct 441 ms 374028 KB Output is correct
52 Correct 246 ms 315360 KB Output is correct