제출 #425345

#제출 시각아이디문제언어결과실행 시간메모리
425345dreezy선물상자 (IOI15_boxes)C++17
10 / 100
3 ms204 KiB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long

long long delivery(int N, int K, int L, int p[]) {
	
	//vector<ll> p(N);
	
	//for(int i = 0; i<n; i++) p[i] = pp[i];
	ll ans = 1e18;
	int mid = L/2;
	
	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;
			if(start >=N) start-= N;
			
			int end = start + K -1;
			if (end >=N){
				end -= N;
				//check if we passed start so we dont double count
				if(end >= first){
					end = first -1;
					if (end == -1) end = N-1;
					//dont double count
				}
				
				swap(end,start);
			}
			

			//cout <<start<<", "<<end<< ": "<< p[start]<<", "<<p[end]<<endl;
			if(p[start] <= mid && p[end] <= mid){//if they are alll in first half
				curans += 2 * p[end];
			}
			//all in second half
			else if(p[start] >= mid && p[end] >= mid){
				curans += 2 * ( L - p[start]);
			}
			else{
				curans += L;
			}
				// do circle	
				
			//cout << rng<<": "<<curans<<" ";
		}
		//cout <<":: "<<curans<<endl<<endl;
		ans = min(curans, ans);
	}
    return ans;
}
/************/
#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...