Submission #441615

#TimeUsernameProblemLanguageResultExecution timeMemory
441615julian33Boxes with souvenirs (IOI15_boxes)C++14
0 / 100
9 ms5048 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 dp[12][12][1<<11],n,k,l,pos[15]; ll make(int at,int rem,int mask){ if(~dp[at][rem][mask]) return dp[at][rem][mask]; ll res=1e18; if(at!=n) res=make(n,k,mask)+min(l-pos[at],pos[at]); if(pos[at]){ if(rem==1) return dp[at][rem][mask]=res; for(int i=0;i<n;i++){ if(!(mask&(1<<i))){ mina(res,make(i,rem-1,mask|(1<<i))+abs(pos[at]-pos[i])); } } } else{ for(int i=0;i<n;i++){ if(!(mask&(1<<i))){ mina(res,make(i,k,mask|(1<<i))+abs(pos[at]-pos[i])); } } } return dp[at][rem][mask]=(res==1e18?0:res); } ll delivery(int N,int K,int L, int positions[]){ n=N; k=K; l=L; for(int i=0;i<n;i++) pos[i]=positions[i]; memset(dp,-1,sizeof(dp)); return make(n,k,0); }

Compilation message (stderr)

boxes.cpp: In function 'll make(int, int, int)':
boxes.cpp:64:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   64 |         res=make(n,k,mask)+min(l-pos[at],pos[at]);
      |                  ^
boxes.cpp:64:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   64 |         res=make(n,k,mask)+min(l-pos[at],pos[at]);
      |                    ^
boxes.cpp:76:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   76 |                 mina(res,make(i,k,mask|(1<<i))+abs(pos[at]-pos[i]));
      |                                 ^
boxes.cpp:80:31: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   80 |     return dp[at][rem][mask]=(res==1e18?0:res);
      |                               ^~~
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:88:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   88 |     return make(n,k,0);
      |                 ^
boxes.cpp:88:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   88 |     return make(n,k,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...