Submission #128261

# Submission time Handle Problem Language Result Execution time Memory
128261 2019-07-10T15:28:45 Z MohamedAhmed04 Boxes with souvenirs (IOI15_boxes) C++14
10 / 100
3 ms 376 KB
#include "boxes.h"
//#include "grader.cpp"
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 1e7 + 5 ;
int pref[MAX] , suff[MAX] ;

long long delivery(int N, int K, int L, int p[])
{
    long long last = 0 ;
    pref[0] = p[0] * 1ll ;
    for(int i = 1 ; i < N ; ++i)
    {
        pref[i] = pref[i-1] ;
        if(i % K == 0)
            pref[i] += (min(p[i-1] , L - p[i-1]) * 1ll + p[i-1] * 1ll) * 1ll ;
        pref[i] += (p[i] * 1ll - p[i-1] * 1ll) * 1ll ;
    }
    suff[N-1] = L - p[N-1] * 1ll ;
    int cnt = 0 ;
    for(int i = N-2 ; i >= 0 ; --i)
    {
        cnt++ ;
        suff[i] = suff[i+1] ;
        if(cnt % K == 0)
            suff[i] += (min(p[i+1] , L - p[i+1]) * 1ll + (L - p[i+1]) * 1ll) * 1ll ;
        suff[i] += (p[i+1] * 1ll - p[i] * 1ll) * 1ll ;
    }
    long long ans = suff[0] + min(L - p[0] , p[0]) * 1ll;
    ans = min(ans , pref[N-1] + min(L - p[N-1] , p[N-1]) * 1ll) ;
    for(int i = 0 ; i < N-1 ; ++i)
        ans = min(ans , (pref[i] + min((L - p[i]) * 1ll , p[i] * 1ll) * 1ll + suff[i+1] + min((L - p[i+1]) * 1ll , p[i+1] * 1ll) * 1ll ) * 1ll ) ;
    return ans ;
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:18:74: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
             pref[i] += (min(p[i-1] , L - p[i-1]) * 1ll + p[i-1] * 1ll) * 1ll ;
                                                                          ^~~
boxes.cpp:19:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         pref[i] += (p[i] * 1ll - p[i-1] * 1ll) * 1ll ;
         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boxes.cpp:21:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     suff[N-1] = L - p[N-1] * 1ll ;
                 ~~^~~~~~~~~~~~~~
boxes.cpp:28:80: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
             suff[i] += (min(p[i+1] , L - p[i+1]) * 1ll + (L - p[i+1]) * 1ll) * 1ll ;
                                                                                ^~~
boxes.cpp:29:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         suff[i] += (p[i+1] * 1ll - p[i] * 1ll) * 1ll ;
         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boxes.cpp:12:15: warning: unused variable 'last' [-Wunused-variable]
     long long last = 0 ;
               ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -