# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
604313 | cheissmart | Scales (IOI15_scales) | C++14 | 1 ms | 212 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 <bits/stdc++.h>
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7;
void init(int T) {
}
void orderCoins() {
vi ans(6); iota(ALL(ans), 1);
auto go = [&] (int x, int y, int z) {
int a = ans[x], b = ans[y], c = ans[z];
int mx = getHeaviest(a, b, c);
int mn = getLightest(a, b, c);
int md = a ^ b ^ c ^ mx ^ mn;
ans[x] = mn, ans[y] = md, ans[z] = mx;
};
auto ins = [&] (int l, int r, int x) {
int ql = -1, qr = -1;
if((ql = getMedian(ans[l], ans[l + 1], ans[x])) == ans[l]) {
int val = ans[x];
ans.erase(ans.begin() + x);
ans.insert(ans.begin(), val);
return;
}
if((qr = getMedian(ans[r - 1], ans[r], ans[x])) == ans[r]) {
int val = ans[x];
ans.erase(ans.begin() + x);
ans.insert(ans.begin() + r + 1, val);
return;
}
for(int i = l; i + 1 <= r; i++) {
int qi = -1;
if(i == l) qi = ql;
else if(i + 1 == r) qi = qr;
else qi = getMedian(ans[i], ans[i + 1], ans[x]);
if(qi == ans[x]) {
int val = ans[x];
ans.erase(ans.begin() + x);
ans.insert(ans.begin() + i + 1, val);
return;
}
}
throw;
};
go(0, 1, 2);
ins(0, 2, 3);
ins(0, 3, 4);
ins(0, 4, 5);
int W[] = {ans[0], ans[1], ans[2], ans[3], ans[4], ans[5]};
answer(W);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |