# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
482756 | dxz05 | Scales (IOI15_scales) | C++14 | 1 ms | 204 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>
using namespace std;
void init(int T) {
/* ... */
}
map<vector<int>, int> mem[4];
int Lightest(int A, int B, int C){
if (mem[0].find({A, B, C}) != mem[0].end()) return mem[0][{A, B, C}];
return mem[0][{A, B, C}] = getLightest(A, B, C);
}
int Median(int A, int B, int C){
if (mem[1].find({A, B, C}) != mem[1].end()) return mem[1][{A, B, C}];
return mem[1][{A, B, C}] = getMedian(A, B, C);
}
int Heaviest(int A, int B, int C){
if (mem[2].find({A, B, C}) != mem[2].end()) return mem[2][{A, B, C}];
return mem[2][{A, B, C}] = getHeaviest(A, B, C);
}
int NextLightest(int A, int B, int C, int D){
if (mem[3].find({A, B, C, D}) != mem[3].end()) return mem[3][{A, B, C, D}];
return mem[3][{A, B, C, D}] = getNextLightest(A, B, C, D);
}
void orderCoins() {
for (int i = 0; i < 4; i++) mem[i].clear();
deque<int> a, b;
for (int i = 1; i <= 6; i += 3){
int A = Lightest(i, i + 1, i + 2);
int B = Median(i, i + 1, i + 2);
int C = i ^ (i + 1) ^ (i + 2) ^ A ^ B;
if (i == 1) a.push_back(A), a.push_back(B), a.push_back(C); else
b.push_back(A), b.push_back(B), b.push_back(C);
}
int W[] = {0, 0, 0, 0, 0, 0};
W[0] = Lightest(a[0], b[0], a[1]);
if (W[0] == a[0]) a.pop_front(); else
b.pop_front();
for (int i = 1; i < 6; i++){
if (a.empty()){
W[i] = b.front();
b.pop_front();
continue;
}
if (b.empty()){
W[i] = a.front();
a.pop_front();
continue;
}
W[i] = Median(W[0], a.front(), b.front());
if (W[i] == a.front()) a.pop_front(); else
b.pop_front();
}
answer(W);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |