Submission #136984

# Submission time Handle Problem Language Result Execution time Memory
136984 2019-07-26T19:58:35 Z arthurconmy Boxes with souvenirs (IOI15_boxes) C++14
100 / 100
957 ms 372184 KB
#include <bits/stdc++.h>

#ifndef ARTHUR_LOCAL
	#include "boxes.h"
#endif

using namespace std;

using ll = long long;

const int MAXN = 10000001; // increase to 10^7 for last subtask

int locs[2][MAXN]; // the locations of the souvenirs on each side of the start
ll dp[2][MAXN];
int side_count[2];
ll ans[MAXN]; // MAXK == MAXN

ll CEIL(int a, int b)
{
	if(a%b == 0) return ll(a/b);
	return ll(a/b) + 1LL;
}

ll delivery(int n, int k, int l, int P[]) 
{
    // intialise things

    for(int i=0; i<MAXN; i++)
    {
    	locs[0][i]=-1;
    	locs[1][i]=-1;
    	ans[i]=1e18;
    }

    // do things

    if(n==1) return 2LL*ll(min(P[0],l-P[0]));

    side_count[0]=0;
    side_count[1]=0;

    for(int i=0; i<n; i++)
    {
    	if(P[i] <= int(l/2))
    	{
    		locs[0][++side_count[0]] = P[i];
    		//cout << "0: " << P[i] << endl;
    	}
    }

    for(int i=n-1; i>=0; i--)
    {
    	if(P[i] > int(l/2))
    	{
    		locs[1][++side_count[1]] = l-P[i];
    	}
    }

    for(int ind=0; ind<=1; ind++) // compute both sides of the dp
    {    	
    	for(int i=1; i<=side_count[ind]; i++)
    	{
    		// calculating dp[ind][i]

    		dp[ind][i] = 2*locs[ind][i] + dp[ind][max(0,i-k)];
    		//cout << ind << " " << i << " " << dp[ind][i] << endl; 
    	
    		// this easy ???
    	}
    }

    // now we need do the residues (mod k) bit
    // should we add the excess residue here? I think yes

    for(int cut=0; cut<=side_count[0]; cut++)
    {
    	// possibly recalculate a minimum for ans[cut % k]
    
    	ll cur = dp[0][side_count[0]-cut];

    	cur += ll(l)*CEIL(cut,k);

    	// cout << cut << " " << cur << endl;

    	ans[cut%k] = min(ans[cut%k], cur);
    }

    ll ret=1e18;

    // int bigk=k;

    // while(bigk<10000000 && bigk != 1) bigk*=k; // PROBABLY CHANGE FOR LAST SUBTASK

    // if(bigk==1) bigk = 10000000;

    ll bigk = 1e9 * ll(k);

    // cout << "here" << endl;

    for(ll cut2=0; cut2<=ll(side_count[1]); cut2++)
    {
    	//cout << "step one" << endl;
    	ll cur = dp[1][side_count[1]-int(cut2)];
		//cout << "step two" << endl;
    	cur += ll(l)*ll(int(cut2/k)) + ans[int((bigk-cut2)%ll(k))];
    	//cout << "step three" << endl;
    	ret = min(ret,cur);
    }

    if(k>=n) ret=min(ret,ll(l));

    return ret;
}

#ifdef ARTHUR_LOCAL

	int A[MAXN];

	int main()
	{
		A[0]=1;
		A[1]=2;
		A[2]=6;
		A[3]=7;


		cout << delivery(4,2,8,A) << endl;
	}

#endif

Compilation message

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:96:19: warning: conversion to 'll {aka long long int}' from 'double' may alter its value [-Wfloat-conversion]
     ll bigk = 1e9 * ll(k);
               ~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 148 ms 157048 KB Output is correct
2 Correct 139 ms 156920 KB Output is correct
3 Correct 138 ms 156920 KB Output is correct
4 Correct 141 ms 156880 KB Output is correct
5 Correct 154 ms 156892 KB Output is correct
6 Correct 140 ms 156892 KB Output is correct
7 Correct 140 ms 156864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 156820 KB Output is correct
2 Correct 139 ms 156876 KB Output is correct
3 Correct 141 ms 156956 KB Output is correct
4 Correct 170 ms 156920 KB Output is correct
5 Correct 142 ms 156820 KB Output is correct
6 Correct 156 ms 156912 KB Output is correct
7 Correct 155 ms 157008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 156920 KB Output is correct
2 Correct 139 ms 156952 KB Output is correct
3 Correct 140 ms 156920 KB Output is correct
4 Correct 139 ms 156976 KB Output is correct
5 Correct 140 ms 156892 KB Output is correct
6 Correct 140 ms 156956 KB Output is correct
7 Correct 138 ms 156920 KB Output is correct
8 Correct 166 ms 156924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 157048 KB Output is correct
2 Correct 139 ms 156920 KB Output is correct
3 Correct 138 ms 156920 KB Output is correct
4 Correct 141 ms 156880 KB Output is correct
5 Correct 154 ms 156892 KB Output is correct
6 Correct 140 ms 156892 KB Output is correct
7 Correct 140 ms 156864 KB Output is correct
8 Correct 139 ms 156820 KB Output is correct
9 Correct 139 ms 156876 KB Output is correct
10 Correct 141 ms 156956 KB Output is correct
11 Correct 170 ms 156920 KB Output is correct
12 Correct 142 ms 156820 KB Output is correct
13 Correct 156 ms 156912 KB Output is correct
14 Correct 155 ms 157008 KB Output is correct
15 Correct 140 ms 156920 KB Output is correct
16 Correct 139 ms 156952 KB Output is correct
17 Correct 140 ms 156920 KB Output is correct
18 Correct 139 ms 156976 KB Output is correct
19 Correct 140 ms 156892 KB Output is correct
20 Correct 140 ms 156956 KB Output is correct
21 Correct 138 ms 156920 KB Output is correct
22 Correct 166 ms 156924 KB Output is correct
23 Correct 148 ms 156880 KB Output is correct
24 Correct 145 ms 156892 KB Output is correct
25 Correct 139 ms 156864 KB Output is correct
26 Correct 138 ms 156920 KB Output is correct
27 Correct 150 ms 157060 KB Output is correct
28 Correct 144 ms 156880 KB Output is correct
29 Correct 186 ms 156920 KB Output is correct
30 Correct 140 ms 156920 KB Output is correct
31 Correct 164 ms 156984 KB Output is correct
32 Correct 175 ms 156892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 157048 KB Output is correct
2 Correct 139 ms 156920 KB Output is correct
3 Correct 138 ms 156920 KB Output is correct
4 Correct 141 ms 156880 KB Output is correct
5 Correct 154 ms 156892 KB Output is correct
6 Correct 140 ms 156892 KB Output is correct
7 Correct 140 ms 156864 KB Output is correct
8 Correct 139 ms 156820 KB Output is correct
9 Correct 139 ms 156876 KB Output is correct
10 Correct 141 ms 156956 KB Output is correct
11 Correct 170 ms 156920 KB Output is correct
12 Correct 142 ms 156820 KB Output is correct
13 Correct 156 ms 156912 KB Output is correct
14 Correct 155 ms 157008 KB Output is correct
15 Correct 140 ms 156920 KB Output is correct
16 Correct 139 ms 156952 KB Output is correct
17 Correct 140 ms 156920 KB Output is correct
18 Correct 139 ms 156976 KB Output is correct
19 Correct 140 ms 156892 KB Output is correct
20 Correct 140 ms 156956 KB Output is correct
21 Correct 138 ms 156920 KB Output is correct
22 Correct 166 ms 156924 KB Output is correct
23 Correct 148 ms 156880 KB Output is correct
24 Correct 145 ms 156892 KB Output is correct
25 Correct 139 ms 156864 KB Output is correct
26 Correct 138 ms 156920 KB Output is correct
27 Correct 150 ms 157060 KB Output is correct
28 Correct 144 ms 156880 KB Output is correct
29 Correct 186 ms 156920 KB Output is correct
30 Correct 140 ms 156920 KB Output is correct
31 Correct 164 ms 156984 KB Output is correct
32 Correct 175 ms 156892 KB Output is correct
33 Correct 204 ms 168508 KB Output is correct
34 Correct 170 ms 168672 KB Output is correct
35 Correct 174 ms 168648 KB Output is correct
36 Correct 215 ms 168632 KB Output is correct
37 Correct 216 ms 168568 KB Output is correct
38 Correct 198 ms 168696 KB Output is correct
39 Correct 199 ms 168700 KB Output is correct
40 Correct 181 ms 168692 KB Output is correct
41 Correct 214 ms 168664 KB Output is correct
42 Correct 191 ms 168840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 157048 KB Output is correct
2 Correct 139 ms 156920 KB Output is correct
3 Correct 138 ms 156920 KB Output is correct
4 Correct 141 ms 156880 KB Output is correct
5 Correct 154 ms 156892 KB Output is correct
6 Correct 140 ms 156892 KB Output is correct
7 Correct 140 ms 156864 KB Output is correct
8 Correct 139 ms 156820 KB Output is correct
9 Correct 139 ms 156876 KB Output is correct
10 Correct 141 ms 156956 KB Output is correct
11 Correct 170 ms 156920 KB Output is correct
12 Correct 142 ms 156820 KB Output is correct
13 Correct 156 ms 156912 KB Output is correct
14 Correct 155 ms 157008 KB Output is correct
15 Correct 140 ms 156920 KB Output is correct
16 Correct 139 ms 156952 KB Output is correct
17 Correct 140 ms 156920 KB Output is correct
18 Correct 139 ms 156976 KB Output is correct
19 Correct 140 ms 156892 KB Output is correct
20 Correct 140 ms 156956 KB Output is correct
21 Correct 138 ms 156920 KB Output is correct
22 Correct 166 ms 156924 KB Output is correct
23 Correct 148 ms 156880 KB Output is correct
24 Correct 145 ms 156892 KB Output is correct
25 Correct 139 ms 156864 KB Output is correct
26 Correct 138 ms 156920 KB Output is correct
27 Correct 150 ms 157060 KB Output is correct
28 Correct 144 ms 156880 KB Output is correct
29 Correct 186 ms 156920 KB Output is correct
30 Correct 140 ms 156920 KB Output is correct
31 Correct 164 ms 156984 KB Output is correct
32 Correct 175 ms 156892 KB Output is correct
33 Correct 204 ms 168508 KB Output is correct
34 Correct 170 ms 168672 KB Output is correct
35 Correct 174 ms 168648 KB Output is correct
36 Correct 215 ms 168632 KB Output is correct
37 Correct 216 ms 168568 KB Output is correct
38 Correct 198 ms 168696 KB Output is correct
39 Correct 199 ms 168700 KB Output is correct
40 Correct 181 ms 168692 KB Output is correct
41 Correct 214 ms 168664 KB Output is correct
42 Correct 191 ms 168840 KB Output is correct
43 Correct 823 ms 274428 KB Output is correct
44 Correct 467 ms 293852 KB Output is correct
45 Correct 517 ms 301764 KB Output is correct
46 Correct 722 ms 372184 KB Output is correct
47 Correct 871 ms 372024 KB Output is correct
48 Correct 902 ms 371940 KB Output is correct
49 Correct 768 ms 356836 KB Output is correct
50 Correct 578 ms 310896 KB Output is correct
51 Correct 957 ms 372092 KB Output is correct
52 Correct 702 ms 313492 KB Output is correct