Submission #101327

# Submission time Handle Problem Language Result Execution time Memory
101327 2019-03-18T13:14:47 Z ansol4328 Boxes with souvenirs (IOI15_boxes) C++11
Compilation error
0 ms 0 KB
#include<vector>
#include<algorithm>

using namespace std;

long long delivery(int N, int K, int L, int *positions)
{
    long long res=0;
    vector<int> lst1, lst2;
    for(int i=0 ; i<N ; i++)
    {
        if(positions[i]>L/2) break;
        lst1.push_back(positions[i]);
        positions[i]=-1;
    }
    for(int i=N-1 ; i>=0 ; i--)
    {
        if(positions[i]==-1) break;
        lst2.push_back(positions[i]);
        positions[i]=-1;
    }
    int idx1=-1, idx2=-1;
    for(int i=K-1 ; i<lst1.size() ; idx1=i, i+=K) res+=2*lst1[i];
    for(int i=K-1 ; i<lst2.size() ; idx2=i, i+=K) res+=2*(L-lst1[i]);
    int rm1=lst1.size()-idx1-1, rm2=lst2.size()-idx2-1;
    int v1=0, v2=l, v3=l;
    if(rm1) v1+=2*lst1[lst1.size()-1];
    if(rm2) v1+=2*(L-lst2[lst2.size()-1]);
    if(rm1+rm2>=K)
    {
        int x=rm1+rm2-K;
        if(x)
        {
            v2+=2*(L-lst2[idx2+x]);
            v3+=2*lst1[idx1+x];
        }
    }
    res+=min(v1,min(v2,v3));
    return res;
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:23:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=K-1 ; i<lst1.size() ; idx1=i, i+=K) res+=2*lst1[i];
                     ~^~~~~~~~~~~~
boxes.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=K-1 ; i<lst2.size() ; idx2=i, i+=K) res+=2*(L-lst1[i]);
                     ~^~~~~~~~~~~~
boxes.cpp:25:29: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
     int rm1=lst1.size()-idx1-1, rm2=lst2.size()-idx2-1;
             ~~~~~~~~~~~~~~~~^~
boxes.cpp:25:53: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
     int rm1=lst1.size()-idx1-1, rm2=lst2.size()-idx2-1;
                                     ~~~~~~~~~~~~~~~~^~
boxes.cpp:26:18: error: 'l' was not declared in this scope
     int v1=0, v2=l, v3=l;
                  ^
boxes.cpp:35:13: error: 'v3' was not declared in this scope
             v3+=2*lst1[idx1+x];
             ^~
boxes.cpp:35:13: note: suggested alternative: 'v2'
             v3+=2*lst1[idx1+x];
             ^~
             v2
boxes.cpp:38:24: error: 'v3' was not declared in this scope
     res+=min(v1,min(v2,v3));
                        ^~
boxes.cpp:38:24: note: suggested alternative: 'v2'
     res+=min(v1,min(v2,v3));
                        ^~
                        v2