Submission #101336

#TimeUsernameProblemLanguageResultExecution timeMemory
101336ansol4328Boxes with souvenirs (IOI15_boxes)C++11
20 / 100
3 ms384 KiB
#include<stdio.h> #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=lst1.size()-1, idx2=lst2.size()-1; for(int i=lst1.size()-1 ; i-K+1>=0 ; idx1=i-K, i-=K) res+=2*lst1[i]; for(int i=lst2.size()-1 ; i-K+1>=0 ; idx2=i-K, i-=K) res+=2*(L-lst2[i]); int rm1=idx1+1, rm2=idx2+1; int v1=0, v2=L, v3=L; if(rm1) v1+=2*lst1[idx1]; if(rm2) v1+=2*(L-lst2[idx2]); if(rm1+rm2>=K) { int x=rm1+rm2-K; if(x) { v2+=2*(L-lst2[x-1]); v3+=2*lst1[x-1]; } } res+=min(v1,min(v2,v3)); return res; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:23:25: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
     int idx1=lst1.size()-1, idx2=lst2.size()-1;
              ~~~~~~~~~~~^~
boxes.cpp:23:45: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
     int idx1=lst1.size()-1, idx2=lst2.size()-1;
                                  ~~~~~~~~~~~^~
boxes.cpp:24:26: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
     for(int i=lst1.size()-1 ; i-K+1>=0 ; idx1=i-K, i-=K) res+=2*lst1[i];
               ~~~~~~~~~~~^~
boxes.cpp:25:26: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
     for(int i=lst2.size()-1 ; i-K+1>=0 ; idx2=i-K, i-=K) res+=2*(L-lst2[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...