Submission #441608

#TimeUsernameProblemLanguageResultExecution timeMemory
441608julian33Boxes with souvenirs (IOI15_boxes)C++14
0 / 100
2093 ms204 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template<typename ...Args> void logger(string vars, Args&&... values) { cerr<<vars<<" = "; string delim=""; (...,(cerr<<delim<<values,delim=", ")); cerr<<"\n"; } #else #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template<typename ...Args> void logger(string vars, Args&&... values) {} #endif #define pb push_back #define sz(x) (int)(x.size()) typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; template<typename T> inline void maxa(T& a,T b){a=max(a,b);} template<typename T> inline void mina(T& a,T b){a=min(a,b);} // ll delivery(int N, int K, int L, int positions[]){ // ll ans=0; // vector<int> pos; // for(int i=0;i<N;i++){ // if(positions[i]) // pos.pb(positions[i]); // } // int n=sz(pos); // vector<ll> pref(n),suff(n); // for(int i=0;i<n;i++){ // if(i<K){ // pref[i]=min(2*pos[i],L); // } else{ // pref[i]=pref[i/K*K-1]+min(2*pos[i],L); // } // } // for(int i=n-1;i>=0;i--){ // if(n-i-1<K){ // suff[i]=min(2*(L-pos[i]),L); // } else{ // suff[i]=suff[n-1-(n-i-1)/K*K+1]+min(2*(L-pos[i]),L); // } // } // ans=min(pref[n-1],suff[0]); // for(int i=0;i<n-1;i++) // mina(ans,pref[i]+suff[i+1]); // return ans; // } ll delivery(int N,int K,int L, int positions[]){ ll ans=1e18; vector<int> Positions; for(int i=0;i<N;i++){ if(positions[i]!=0) Positions.pb(positions[i]); } int n=sz(Positions); vector<int> pos(n); for(int i=0;i<n;i++){ pos[n-i-1]=1; sort(pos.begin(),pos.end()); do{ if(pos.back()!=1){ continue; } vector<ll> pref(n),suff(n); int pre=-1; ll cur=0; for(int j=0;j<n;j++){ if(j) pref[j]=pref[j-1]; if(pos[j]){ if(j-pre>K){ cur=1e18; break; } pref[j]+=min(L,2*Positions[j]); pre=j; } } if(cur==1e18) continue; for(int j=n-1;j>=0;j--){ if(j!=n-1) suff[j]=suff[j+1]; if(pos[j]) suff[j]+=min(L,2*(L-Positions[i])); } cur=min(suff[0],pref[n-1]); for(int i=0;i<n-1;i++) mina(cur,pref[i]+suff[i+1]); mina(ans,cur); } while(next_permutation(pos.begin(),pos.end())); } return ans; }

Compilation message (stderr)

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:88:16: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   88 |             if(cur==1e18)
      |                ^~~
boxes.cpp:97:21: warning: declaration of 'i' shadows a previous local [-Wshadow]
   97 |             for(int i=0;i<n-1;i++)
      |                     ^
boxes.cpp:66:13: note: shadowed declaration is here
   66 |     for(int i=0;i<n;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...