# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242862 | godwind | Scales (IOI15_scales) | C++14 | 5 ms | 384 KiB |
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 "scales.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <functional>
using namespace std;
#define all(v) v.begin(), v.end()
mt19937 rnd(rand());
void init(int T) {
/* ... */
}
int mex(int i, int j) {
for (int x = 1; x <= 6; ++x) {
if (x != i && x != j) {
return x;
}
}
return -1;
}
vector<int> proceed(int a, int b, int c) {
int x = getLightest(a, b, c);
int y = getMedian(a, b, c);
int z = a + b + c - x - y;
vector<int> v;
v.emplace_back(x);
v.emplace_back(y);
v.emplace_back(z);
return v;
}
void insert(vector<int> &a, int x, int pos) {
if (pos == (int)a.size()) {
a.emplace_back(x);
} else {
vector<int> kek;
while ((int)a.size() > pos) {
kek.emplace_back(a.back());
a.pop_back();
}
a.emplace_back(x);
while (!kek.empty()) {
a.emplace_back(kek.back());
kek.pop_back();
}
}
}
void add(vector<int> &a, int x) {
if (a.size() == 3) {
int lb = getNextLightest(a[0], a[1], a[2], x);
if (lb == a[1]) {
insert(a, x, 1);
} else if (lb == a[2]) {
insert(a, x, 2);
} else {
if (getLightest(x, a[0], a[1]) == x) {
insert(a, x, 0);
} else {
insert(a, x, 3);
}
}
} else if (a.size() == 4) {
int lb = getNextLightest(a[1], a[2], a[3], x);
for (int i = 2; i <= 3; ++i) {
if (lb == a[i]) {
insert(a, x, i);
return;
}
}
if (getLightest(a[0], a[1], x) == x) {
insert(a, x, 0);
} else {
if (getMedian(a[0], a[1], x) == x) {
insert(a, x, 1);
} else {
insert(a, x, 4);
}
}
} else {
int lb = getNextLightest(a[2], a[3], a[4], x);
for (int i = 3; i <= 4; ++i) {
if (lb == a[i]) {
insert(a, x, i);
return;
}
}
int new_lb = getNextLightest(a[0], a[1], a[2], x);
for (int i = 1; i <= 2; ++i) {
if (new_lb == a[i]) {
insert(a, x, i);
return;
}
}
if (getLightest(a[0], a[1], x) == x) {
insert(a, x, 0);
} else {
insert(a, x, 5);
}
}
}
void orderCoins() {
/* ... */
int W[] = {1, 2, 3, 4, 5, 6};
vector<int> v;
for (int i = 1; i <= 6; ++i) {
v.emplace_back(i);
}
vector<int> a = proceed(v[0], v[1], v[2]);
for (int i = 3; i < 6; ++i) {
add(a, v[i]);
}
for (int i = 0; i < 6; ++i) W[i] = a[i];
answer(W);
}
/*vector<int> A = proceed(1, 2, 3);
vector<int> B = proceed(4, 5, 6);
vector<int> ans;
int F = 0, S = 0;
for (int it = 0; it < 6; ++it) {
if (F == 3) {
ans.emplace_back(B[S++]);
} else if (S == 3) {
ans.emplace_back(A[F++]);
} else {
int rest = -1;
if (F + 1 < 3) rest = A[F + 1];
if (S + 1 < 3) rest = B[S + 1];
if (rest == -1) {
rest = A[0];
if (getMedian(A[F], B[S], rest) == A[F]) {
ans.emplace_back(A[F++]);
} else {
ans.emplace_back(B[S++]);
}
} else {
if (getLightest(A[F], B[S], rest) == A[F]) {
ans.emplace_back(A[F++]);
} else {
ans.emplace_back(B[S++]);
}
}
}
}
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |