제출 #268544

#제출 시각아이디문제언어결과실행 시간메모리
268544A02선물상자 (IOI15_boxes)C++14
35 / 100
1 ms384 KiB
#include "boxes.h" #include <vector> #include <set> #include <algorithm> #include <utility> #include <iostream> using namespace std; long long delivery(int N, int K, int L, int p[]) { vector<long long> left_positions; vector<long long> right_positions; long long no_round_trips = 0; for (int i = 0; i < N; i++){ if (p[i] <= L/2){ left_positions.push_back(p[i]); } } for (int i = N - 1; i >= 0; i--){ if (p[i] > L/2){ right_positions.push_back(L - p[i]); } } int current_boxes = 0; while (left_positions.size() > 0){ no_round_trips += left_positions[left_positions.size() - 1] * 2; current_boxes = K; for (;left_positions.size() && current_boxes > 0; current_boxes--){ left_positions.pop_back(); } } while (right_positions.size() > 0){ no_round_trips += right_positions[right_positions.size() - 1] * 2; current_boxes = K; for (; right_positions.size() && current_boxes > 0; current_boxes--){ right_positions.pop_back(); } } long long one_round_trip = L; for (int i = 0; i < N; i++){ if (p[i] <= L/2){ left_positions.push_back(p[i]); } } for (int i = N - 1; i >= 0; i--){ if (p[i] > L/2){ right_positions.push_back(L - p[i]); } } current_boxes = K; while(current_boxes > 0){ if (right_positions.size() && left_positions.size() && left_positions[left_positions.size() - 1] > right_positions[right_positions.size() - 1]){ left_positions.pop_back(); } else { if (right_positions.size() == 0 && left_positions.size()){ left_positions.pop_back(); } if (right_positions.size()){ right_positions.pop_back(); } } current_boxes--; } current_boxes = 0; while (left_positions.size() > 0){ one_round_trip += left_positions[left_positions.size() - 1] * 2; current_boxes = K; for (;left_positions.size() && current_boxes > 0; current_boxes--){ left_positions.pop_back(); } } while (right_positions.size() > 0){ one_round_trip += right_positions[right_positions.size() - 1] * 2; current_boxes = K; for (; right_positions.size() && current_boxes > 0; current_boxes--){ right_positions.pop_back(); } } //cout << min(one_round_trip, no_round_trips) << endl; //cout << no_round_trips << endl; return min(one_round_trip, no_round_trips); return 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...