Submission #426088

#TimeUsernameProblemLanguageResultExecution timeMemory
426088dreezy선물상자 (IOI15_boxes)C++17
50 / 100
2080 ms12016 KiB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long

long long delivery(int N, int K, int LL, int pp[]) {
	
	//vector<ll> p(N);
	
	ll L = LL;
	ll p[N];
	for(int i =0; i<N; i++) p[i] = pp[i];
	//for(int i = 0; i<n; i++) p[i] = pp[i];
	ll ans = 1e18;
	ll mid = L/2;
	int midind = N;
	for(int i =0; i<N; i++){
		if(p[i] > mid){
			midind = i;
			break;
		} 
	}
	

	//cout << midind<<endl;
	int best = -1;
	for(int first = 0; first< N; first++){
		ll curans = 0;
		//cout << first<<":: "<<endl;
		for(int rng = first; rng < N + first; rng += K){
			int start = rng;
			
			int end = start + K -1;
			int mstart = start % N;
			int mend = end % N;
			if(end - N >= first){
				end = first - 1 + N;
				mend = end % N;
			}
			//cout << start<<"->"<<end<<", "<<mstart<<"->"<<mend<<endl;
			if(end < N){
							
				//cout <<start<<", "<<end<< ": "<< p[start]<<", "<<p[end]<<endl;
				if(end< midind){//if they are alll in first half
					curans += 2 * p[end];
				}
				//all in second half
				else if(start >= midind){
					curans += 2 * ( L - p[start]);
				}
				else{
					//cout <<"hi"<<endl;
					curans += min(L, 2*p[midind - 1] + 2 * (L-p[midind] ));
				}
			}
			else{
				if( start < N){
					if(start < midind){
						curans += L;
					}
					else if(mend >= midind){
						curans += L;
					}
					else{
					//cout <<"bye"<<endl;
						curans += min(L , 2 * p[mend] + 2 * (L-p[start]) );
					}
				}
				else{
					if(mend< midind){//if they are alll in first half
					curans += 2 * p[mend];
					}
					//all in second half
					else if(mstart >= midind){
						curans += 2 * ( L - p[mstart]);
					}
					else{
					//cout <<"bye"<<endl;
						curans += min(L, 2*p[midind - 1] + 2 * (L-p[midind])   );
					}
					
				}
				
			}
				// do circle	
				
			//cout << rng<<": "<<curans<<endl;
		}
		//cout <<":: "<<curans<<endl<<endl;
		ans = min(curans, ans);
		
		if(ans == curans)
			best = first;
		//cout << curans<<", ";
	}
	//cout <<endl;
	//cout << best<<endl;
    return ans;
}
/************/

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:26:6: warning: variable 'best' set but not used [-Wunused-but-set-variable]
   26 |  int best = -1;
      |      ^~~~
#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...