Submission #112976

#TimeUsernameProblemLanguageResultExecution timeMemory
112976andremfqBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
2 ms408 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; 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); resp3+=(qtdk==0) ? 0 : 2*v1.back(); 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); resp=min(resp1+resp2,resp1+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:78: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:54: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--)
            ~~~~~~~~~^~
#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...