#include "scales.h"
#include<bits/stdc++.h>
using namespace std;
void init(int T)
{
/* ... */
}
void sort_range(int l, int r, int w[])
{
int a = w[l], b = w[l + 1], c = w[r];
///cout << "sort range " << a << " " << b << " " << c << endl;
int mid = getMedian(a, b, c);
int low = getLightest(a, b, c);
int high = a;
if (low == a || mid == a)
{
high = b;
if (mid == b || low == b)
high = c;
}
w[l] = low;
w[l + 1] = mid;
w[r] = high;
}
void merge_sort(int w[])
{
vector < int > res;
int var =getNextLightest(w[0], w[1], w[2], w[4]);
if (var == w[1])
{
res.push_back(w[0]);
res.push_back(w[4]);
res.push_back(w[1]);
res.push_back(w[2]);
int mid = getMedian(w[0], w[4], w[3]);
if (mid == w[0])
res.insert(res.begin() + 0, w[3]);
else
res.insert(res.begin() + 1, w[3]);
mid = getMedian(w[1], w[2], w[5]);
if (mid == w[1])
{
res.insert(res.begin() + 2, w[5]);
}
else if (mid == w[5])
{
res.insert(res.begin() + 3, w[5]);
}
else if (mid == w[2])
{
res.insert(res.begin() + 4, w[5]);
}
}
else
{
int lf = 0, rf = 3;
int ch = getMedian(w[0], w[1], w[3]);
int lightest;
if (ch == w[1])
{
lightest = w[0];
res.push_back(w[0]);
res.push_back(w[1]);
lf += 2;
}
else if (ch == w[3])
{
lightest = w[0];
res.push_back(w[0]);
res.push_back(w[3]);
lf ++;
rf ++;
}
else
{
lightest = w[3];
res.push_back(w[3]);
rf ++;
}
while(lf <= 2 && rf <= 5 && (3 - lf + 6 - rf > 3))
{
if (getHeaviest(w[lf], w[rf], lightest) == w[lf])
res.push_back(w[rf ++]);
else
res.push_back(w[lf ++]);
}
if (rf > 5)
while(lf <= 2)
res.push_back(w[lf ++]);
if (lf > 5)
while(rf <= 5)
res.push_back(w[rf ++]);
if (lf == 1)
{
int mid = getMedian(w[lf], w[lf + 1], w[rf]);
if (mid == w[lf])
{
res.push_back(w[rf]);
res.push_back(w[lf]);
res.push_back(w[lf + 1]);
}
else if (mid == w[lf + 1])
{
res.push_back(w[lf]);
res.push_back(w[lf + 1]);
res.push_back(w[rf]);
}
else if (mid == w[rf])
{
res.push_back(w[lf]);
res.push_back(w[rf]);
res.push_back(w[lf + 1]);
}
}
else if (rf == 4)
{
int mid = getMedian(w[lf], w[rf], w[rf + 1]);
if (mid == w[rf])
{
res.push_back(w[lf]);
res.push_back(w[rf]);
res.push_back(w[rf + 1]);
}
else if (mid == w[rf + 1])
{
res.push_back(w[rf]);
res.push_back(w[rf + 1]);
res.push_back(w[lf]);
}
else if (mid == w[lf])
{
res.push_back(w[rf]);
res.push_back(w[lf]);
res.push_back(w[rf + 1]);
}
}
}
for (int i = 0; i < res.size(); i ++)
w[i] = res[i];
}
void orderCoins()
{
/* ... */
int W[] = {1, 2, 3, 4, 5, 6};
sort_range(0, 2, W);
sort_range(3, 5, W);
/**for (int i = 0; i < 6; i ++)
cout << W[i] << " ";
cout << endl;
exit(0);*/
merge_sort(W);
answer(W);
}
Compilation message
scales.cpp: In function 'void init(int)':
scales.cpp:6:15: warning: unused parameter 'T' [-Wunused-parameter]
6 | void init(int T)
| ~~~~^
scales.cpp: In function 'void merge_sort(int*)':
scales.cpp:153:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
153 | for (int i = 0; i < res.size(); i ++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
23 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
24 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
25 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
26 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
27 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
28 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
29 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
31 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
32 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
33 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
34 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
35 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
36 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
37 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
38 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
39 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
40 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |