Submission #238882

#TimeUsernameProblemLanguageResultExecution timeMemory
238882lakshith_Boxes with souvenirs (IOI15_boxes)C++14
20 / 100
5 ms384 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second using namespace std; inline void io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } inline ll Min(ll a,ll b){ return a<b?a:b; } inline ll Max(ll a,ll b){ return a>b?a:b; } ll delivery(int n,int k,int L,int positions[]){ ll ans; if(k==1){ ans = 0; for(int i=0;i<n;i++){ ans += 2*Min(positions[i],L-positions[i]); } }else if(k==n){ pair<int,int> l,r; for(int i=0;i<n;i++){ if(positions[i]<(L/2)){ l.f = Min(positions[i],l.f); l.s = Max(positions[i],l.s); }else{ r.f = Min(L-positions[i],r.f); r.s = Max(L-positions[i],r.s); } } ans = min(L,2*r.s+2*l.s); }else{ int l[n]; int r[n]; int g = k; int pos = 0; int prev = 0; for(int i=0;i<n;i++){ l[i]=prev; int dis = positions[i]-pos; if(g==0){ l[i] += pos+positions[i]; prev = l[i]; l[i] += Min(positions[i],L-positions[i]); g=k; g--; pos = positions[i]; }else{ l[i] += dis; prev = l[i]; l[i] += Min(positions[i],L-positions[i]); g--; pos = positions[i]; } pos = 0; g = k; prev=0; for(int i=n-1;i>=0;i--){ positions[i] = L-positions[i]; r[i]=prev; int dis = positions[i]-pos; if(g==0){ r[i] += pos+positions[i]; prev = r[i]; r[i] += Min(positions[i],L-positions[i]); g=k; g--; pos = positions[i]; }else{ r[i] += dis; prev = r[i]; r[i] += Min(positions[i],L-positions[i]); g--; pos = positions[i]; } } } // for(int i=0;i<n;i++) // cout << l[i] << "\t"; // cout << "\n"; // for(int i=0;i<n;i++) // cout << r[i] << "\t"; // cout << "\n"; ll MIN = INT_MAX; for(int i=0;i<n-1;i++){ MIN = Min(MIN,l[i]+r[i+1]); } MIN = Min(l[n-1],MIN); MIN = Min(r[0],MIN); ans = MIN; } return ans; } // int main(){ // io_setup(); // int arr[] = {1,2,5}; // cout << delivery(3,2,8,arr); // }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:28:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         l.f = Min(positions[i],l.f);
               ~~~^~~~~~~~~~~~~~~~~~
boxes.cpp:29:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         l.s = Max(positions[i],l.s);
               ~~~^~~~~~~~~~~~~~~~~~
boxes.cpp:31:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         r.f = Min(L-positions[i],r.f);
               ~~~^~~~~~~~~~~~~~~~~~~~
boxes.cpp:32:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         r.s = Max(L-positions[i],r.s);
               ~~~^~~~~~~~~~~~~~~~~~~~
boxes.cpp:48:48: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         l[i] += Min(positions[i],L-positions[i]);
                                                ^
boxes.cpp:55:48: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         l[i] += Min(positions[i],L-positions[i]);
                                                ^
boxes.cpp:62:15: warning: declaration of 'i' shadows a previous local [-Wshadow]
       for(int i=n-1;i>=0;i--){
               ^
boxes.cpp:42:13: note: shadowed declaration is here
     for(int i=0;i<n;i++){
             ^
boxes.cpp:65:13: warning: declaration of 'dis' shadows a previous local [-Wshadow]
         int dis = positions[i]-pos;
             ^~~
boxes.cpp:44:11: note: shadowed declaration is here
       int dis = positions[i]-pos;
           ^~~
boxes.cpp:69:50: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
           r[i] += Min(positions[i],L-positions[i]);
                                                  ^
boxes.cpp:76:50: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
           r[i] += Min(positions[i],L-positions[i]);
                                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...