Submission #112977

#TimeUsernameProblemLanguageResultExecution timeMemory
112977andremfqBoxes with souvenirs (IOI15_boxes)C++17
0 / 100
2 ms384 KiB
#include<bits/stdc++.h> #include"boxes.h" #define debug(args...) //fprintf(stderr,args) using namespace std; const int MAXN=10000010; int N,K,L,POS[MAXN]; long long int RESP,resp; vector<long long int> v1,v2; long long int delivery(int n,int k,int l,int pos[]) { long long int resp1=0,resp2=0,resp3=0,resp4=0; int qtdk=0,qtdk2=0,qtdk3=0; sort(pos,pos+n); for(int i=0;i<n;i++) { if(l/2>=pos[i]) v1.push_back(pos[i]); else v2.push_back(pos[i]); } for(int i=0;i<v1.size();i++) debug("v1[%d] = %d\n",i,v1[i]); debug("\n\n"); for(int i=0;i<v2.size();i++) debug("v2[%d] = %d\n",i,v2[i]); debug("\n\n"); for(int i=0;i<v1.size();i++) { qtdk++; if(qtdk==k) qtdk=0, resp1+=2*v1[i]; } debug("resp = %d\n",resp1); int suv=(qtdk==0) ? 0 : k-qtdk; debug("suv = %d\n",suv); resp2+=l; for(int i=v2.size()-1;i>=suv;i--) { debug("RESP2 = %d\n",resp2); debug("I = %d\n",i); qtdk2++; if(i==suv && qtdk2!=k) resp2+=2*(l-v2[i]); if(qtdk2==k) qtdk2=0, resp2+=2*(l-v2[i]); } debug("resp2 = %d\n",resp2); for(int i=v2.size()-1;i>=0;i--) { qtdk3++; if(i==0 && qtdk3!=k) resp3+=2*(l-v2[i]); if(qtdk3==k) qtdk2=0, resp3+=2*(l-v2[i]); } debug("resp3 = %d\n",resp3); for(int i=v1.size()%k+k-1;i<v1.size();i+=k) { resp3+=2*v1[i]; } debug("resp3 = %d\n",resp3); resp=min(resp1+resp2,resp3); return resp; } /* int main () { scanf("%d %d %d",&N,&K,&L); for(int i=0;i<N;i++) scanf("%d",&POS[i]); RESP=delivery(N,K,L,POS); printf("%lld",RESP); } /* 3 2 8 1 2 5 */

Compilation message (stderr)

boxes.cpp:85:1: warning: "/*" within comment [-Wcomment]
 /*
  
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:24:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v1.size();i++) debug("v1[%d] = %d\n",i,v1[i]);
              ~^~~~~~~~~~
boxes.cpp:27:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v2.size();i++) debug("v2[%d] = %d\n",i,v2[i]);
              ~^~~~~~~~~~
boxes.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v1.size();i++)
              ~^~~~~~~~~~
boxes.cpp:42:21: warning: conversion to 'int' from 'std::vector<long long int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  for(int i=v2.size()-1;i>=suv;i--)
            ~~~~~~~~~^~
boxes.cpp:53:21: warning: conversion to 'int' from 'std::vector<long long int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  for(int i=v2.size()-1;i>=0;i--)
            ~~~~~~~~~^~
boxes.cpp:62:25: warning: conversion to 'int' from 'std::vector<long long int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  for(int i=v1.size()%k+k-1;i<v1.size();i+=k)
            ~~~~~~~~~~~~~^~
boxes.cpp:62:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=v1.size()%k+k-1;i<v1.size();i+=k)
                            ~^~~~~~~~~~
boxes.cpp:13:40: warning: unused variable 'resp4' [-Wunused-variable]
  long long int resp1=0,resp2=0,resp3=0,resp4=0;
                                        ^~~~~
#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...