제출 #127993

#제출 시각아이디문제언어결과실행 시간메모리
127993MoNsTeR_CuBe선물상자 (IOI15_boxes)C++17
10 / 100
170 ms828 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; long long delivery(int N, int K, int L, int p[]) { #define int long long if(N <= 10){ vector< int > v(N); for(int i = 0; i < N; i++){ v[i] = p[i]; } int ans = numeric_limits<int>::max(); do{ for(int a : v) cout << a << ' '; cout << endl; int last = 0; int curr = K; int cost = 0; for(int i = 0; i < (int) v.size(); i++){ if(abs(v[i]-last) + (curr ? 0 : min(last, abs(L-last))) < min(abs(L-v[i]), v[i]) + min(abs(L-last), last)){ if(!curr){ curr = K; cost += min(last, abs(L-last)); } curr--; cost += abs(v[i]-last); }else{ curr = K-1; cost += min(abs(L-v[i]), v[i]) + min(abs(L-last), last); } cout << "STEP " << cost << endl; last = v[i]; } ans = min(ans, cost + min(last, L-last)); cout << "COST " << cost + min(last, L-last) << endl; }while(next_permutation(v.begin(), v.end())); return ans; } vector< int > left; int curr = K; int last = 0; int currCost = 0; for(int i = 0; i < N; i++){ left.push_back(p[i]-last + currCost); curr--; if(curr == 0){ curr = K; currCost += 2*p[i]; } currCost += p[i]-last; last = p[i]; } //left.push_back(L-last); /*for(int a : left) cout << a << ' '; cout << endl;*/ vector< int > right; curr = K; last = L; currCost = 0; for(int i = N-1; i >= 0; i--){ right.push_back(last - p[i] + currCost); curr--; if(curr == 0){ curr = K; currCost += 2*(L-p[i]); } currCost += last - p[i]; last = p[i]; } //right.push_back(last + currCost); /*for(int a : right) cout << a << ' '; cout << endl;*/ //reverse(right.begin(), right.end()); int ans = min(right[N - 1] + min(p[0], L-p[0]), left[N-1] + min(L-p[N-1], p[N-1])); for(int i = 0; i < N; i++){ if(N - 2 - i < 0) continue; //cout << "INDEX " << i << ' ' << left[i] << ' ' << right[N-2-i] << ' ' << min(p[i], L-p[i]) << ' ' << min(p[i+1], L-p[i+1]) << endl; //cout << p[N-2-i] << ' ' << L-p[N-2-i] << endl; ans = min(ans, left[i] + right[N - 2 - i] + min(p[i],L-p[i]) + min(p[i+1],L-p[i+1])); } return ans; #undef int }
#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...