This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "boxes.h"
#include <bits/stdc++.h>
#include <set>
long long delivery(int numTeams, int capacity, int numSections, int p[])
{
auto DistTo0 = [&] (int x)
{
return std::min(x, numSections - x);
};
int numL = 0;
int numR = 0;
std::vector<int> numTeamsPerSection(numSections);
std::set<int> teamPositions;
for (int i = 0; i < numTeams; i++)
{
if (p[i] != 0)
{
numTeamsPerSection[p[i]]++;
if (p[i] * 2 < numSections)
numL++;
else
numR++;
}
}
long long sec = 0;
while (numL > 0 || numR > 0)
{
int boxes = capacity;
int pos = 0;
int dir;
if (numR > numL)
{
dir = -1;
}
else
{
dir = 1;
}
while (true)
{
if (pos != 0)
{
int numToGive = std::min(numTeamsPerSection[pos], boxes);
numTeamsPerSection[pos] -= numToGive;
boxes -= numToGive;
if (pos * 2 < numSections)
numL -= numToGive;
else
numR -= numToGive;
if (boxes <= 0 || (numL == 0 && numR == 0))
{
sec += DistTo0(pos);
break;
}
}
pos += dir;
sec++;
if (pos == 0 || pos == numSections)
break;
if (pos == -1)
pos = numSections - 1;
}
}
return sec;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |