#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 |
1 |
Runtime error |
382 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Runtime error |
412 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Runtime error |
363 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
382 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
382 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
382 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |