Submission #416021

#TimeUsernameProblemLanguageResultExecution timeMemory
416021victoriadBoxes with souvenirs (IOI15_boxes)C++14
10 / 100
2 ms284 KiB
#include "boxes.h" #include <vector> using namespace std; int n,n2; long long int dfs(bool b,int K,int box[],long long int L,int N,int tk){ long long int m=1e12,j=1e12; for(int i=0;i<N;i++){ if(box[i]!=-1){ int x=box[i]; if(1<=K){ K--; if(x<=L/2)b=false; if(x<=L/2)m=x; else if(j==1e12){ j=x; if(2*m+2*(L-j)<=L){ return 2*m; } } n--; box[i]=-1; } if(K==0||n==0){ if((x<=L/2))return 2*x; else if(b){ return 2*(L-j); } else{ return min(L,2*(L-j)+2*m); } } } } } int ultimo(int p[],int N,int L){ int low=0,hi=N-1,r=0; while(low<=hi){ int m=low+(hi-low); if(p[m]<=L/2){ r=m; low=m+1; } else{ hi=m-1; } } return r; } int medio(int p[],int K,int L,int N,int r){ long long ans=0; for(int i=r+1;i<N;i+=K){ ans+=2*(L-p[i]); } for(int i=r;i>=0;i-=K){ ans+=2*p[i]; } return ans; } long long int dfs2(bool b,int K, int box2[],long long int L,int N,int tk){ long long int j=0,m=1e12; for(int i=N-1;i>=0;i--){ if(box2[i]!=-1){ int x=box2[i]; if(K>=1){ K--; if(x>L/2){ b=false; j=x; } else if(m==1e12){ m=x; if(2*m+2*(L-j)<=L){ return 2*(L-j); } } n2--; box2[i]=-1; } if(K==0||n2==0){ if(x>L/2)return 2*(L-x); else if(b){ return 2*m; } else{ return min(L,2*m+2*(L-j)); } } } } } long long delivery(int N, int K, int L, int p[]) { n=N; n2=N; int u=ultimo(p,N,L); long long int r1=medio(p,K,L,N,u); for(int i=0;i<N;i++){ if(p[i]==0){ p[i]=-1; n--; n2--; } else{ break; } } int p2[N]; for(int i=0;i<N;i++)p2[i]=p[i]; long long int r=0; long long int r2=0; while(n>0){ bool b=true; r+=dfs(b,K,p,L,N,K); } while(n2>0){ bool b=true; r2+=dfs2(b,K,p2,L,N,K); } return min(r,min(r1,r2)); }

Compilation message (stderr)

boxes.cpp: In function 'long long int dfs(bool, int, int*, long long int, int, int)':
boxes.cpp:16:13: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   16 |     else if(j==1e12){
      |             ^
boxes.cpp:7:68: warning: unused parameter 'tk' [-Wunused-parameter]
    7 | long long int dfs(bool b,int K,int box[],long long int L,int N,int tk){
      |                                                                ~~~~^~
boxes.cpp: In function 'int medio(int*, int, int, int, int)':
boxes.cpp:60:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   60 |     return ans;
      |            ^~~
boxes.cpp: In function 'long long int dfs2(bool, int, int*, long long int, int, int)':
boxes.cpp:75:21: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   75 |             else if(m==1e12){
      |                     ^
boxes.cpp:64:71: warning: unused parameter 'tk' [-Wunused-parameter]
   64 | long long int dfs2(bool b,int K, int box2[],long long int L,int N,int tk){
      |                                                                   ~~~~^~
boxes.cpp: In function 'long long int dfs(bool, int, int*, long long int, int, int)':
boxes.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
   36 | }
      | ^
boxes.cpp: In function 'long long int dfs2(bool, int, int*, long long int, int, int)':
boxes.cpp:95:1: warning: control reaches end of non-void function [-Wreturn-type]
   95 | }
      | ^
#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...