# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
287742 | amoo_safar | 저울 (IOI15_scales) | C++17 | 2 ms | 360 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 all(x) x.begin(), x.end()
using namespace std;
struct Query {
int type;
int a, b, c, d;
int res;
Query (int _type, int _a, int _b, int _c, int _d, int _res){
type = _type;
a = _a;
b = _b;
c = _c;
d = _d;
res = _res;
}
};
vector<Query> Asked;
int AskMin(int a, int b, int c){
int res = getLightest(a, b, c);
Query nw(0, a, b, c, -1, res);
Asked.push_back(nw);
return res;
}
int AskMax(int a, int b, int c){
int res = getHeaviest(a, b, c);
Query nw(1, a, b, c, -1, res);
Asked.push_back(nw);
return res;
}
int AskMedian(int a, int b, int c){
int res = getMedian(a, b, c);
Query nw(2, a, b, c, -1, res);
Asked.push_back(nw);
return res;
}
int AskNext(int a, int b, int c, int d){
int res = getNextLightest(a, b, c, d);
Query nw(3, a, b, c, d, res);
Asked.push_back(nw);
return res;
}
int Next(int a, int b, int c, int d){
vector<int> Arr = {a, b, c};
sort(all(Arr));
auto it = lower_bound(all(Arr), d);
if(it == Arr.end()) return Arr[0];
return *it;
}
void Solve(){
vector<int> per(7);
int W[] = {-1, -1, -1, -1, -1, -1};
iota(per.begin(), per.end(), 0);
int mn, mx, sm;
do {
bool flg = true;
for(auto X : Asked){
mn = min({per[X.a], per[X.b], per[X.c]});
mx = max({per[X.a], per[X.b], per[X.c]});
sm = per[X.a] + per[X.b] + per[X.c];
if(X.type == 0)
flg &= (per[X.res] == mn);
if(X.type == 1)
flg &= (per[X.res] == mx);
if(X.type == 2)
flg &= (per[X.res] == sm - mn - mx);
if(X.type == 3)
flg &= (per[X.res] == Next(per[X.a], per[X.b], per[X.c], per[X.d]));
}
if(!flg) continue;
for(int i = 1; i <= 6; i++)
W[per[i] - 1] = i;
answer(W);
return ;
} while(next_permutation(per.begin() + 1, per.end()));
assert(false);
return ;
}
void init(int T) {
assert(T != -1);
return ;
}
void orderCoins(){
Asked.clear();
int W[] = {1, 2, 3, 4, 5, 6};
int S4[] = {0, 0, 0, 0}, p = 0;
int res, A, B, C, D, E, F;
int V[] = {1, 2, 3, 4, 5, 6};
res = AskMax(1, 2, 3);
if(res == 2) swap(V[1], V[0]);
if(res == 3) swap(V[2], V[0]);
res = AskMedian(4, 5, 6);
if(res == 5) swap(V[4], V[3]);
if(res == 6) swap(V[5], V[3]);
int tmp;
tmp = AskNext(V[2], V[4], V[5], V[1]);
// Next(V[2], V[4], V[5], V[1]);
if(tmp == V[2]){ // 26
int a2 = 1, b2 = 4, c2 = 5;
int tmp2 = AskMin(V[a2], V[b2], V[c2]);
if(tmp2 == V[a2]){ // 8
int a3 = 3, b3 = 4, c3 = 5;
int tmp3 = AskNext(V[a3], V[b3], V[c3], V[0]);
if(tmp3 == V[a3]){ // 2
int a4 = 0, b4 = 4, c4 = 5;
int tmp4 = AskMin(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[b3]){ // 3
int a4 = 0, b4 = 3, c4 = 4;
int tmp4 = AskMax(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[c3]){ // 3
int a4 = 0, b4 = 4, c4 = 5;
int tmp4 = AskMax(V[a4], V[b4], V[c4]);
Solve();
return ;
}
}
if(tmp2 == V[b2]){ // 9
int a3 = 1, b3 = 2, c3 = 3;
int tmp3 = AskMedian(V[a3], V[b3], V[c3]);
if(tmp3 == V[a3]){ // 3
int a4 = 0, b4 = 2, c4 = 5;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[b3]){ // 3
int a4 = 0, b4 = 3, c4 = 5;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[c3]){ // 3
int a4 = 0, b4 = 1, c4 = 5;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
}
if(tmp2 == V[c2]){ // 9
int a3 = 1, b3 = 2, c3 = 3;
int tmp3 = AskMedian(V[a3], V[b3], V[c3]);
if(tmp3 == V[a3]){ // 3
int a4 = 0, b4 = 1, c4 = 4;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[b3]){ // 3
int a4 = 0, b4 = 3, c4 = 4;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[c3]){ // 3
int a4 = 0, b4 = 1, c4 = 4;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
}
}
if(tmp == V[5]) swap(V[4], V[5]);
if(tmp == V[4]){ // 27
int a2 = 2, b2 = 4, c2 = 5;
int tmp2 = AskMin(V[a2], V[b2], V[c2]);
if(tmp2 == V[a2]){ // 9
int a3 = 0, b3 = 4, c3 = 5;
int tmp3 = AskMax(V[a3], V[b3], V[c3]);
if(tmp3 == V[a3]){ // 3
int a4 = 1, b4 = 3, c4 = 4;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[b3]){ // 3
int a4 = 0, b4 = 1, c4 = 3;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[c3]){ // 3
int a4 = 0, b4 = 3, c4 = 4;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
}
if(tmp2 == V[b2]){ // 9
int a3 = 1, b3 = 2, c3 = 3;
int tmp3 = AskMax(V[a3], V[b3], V[c3]);
if(tmp3 == V[a3]){ // 3
int a4 = 2, b4 = 3, c4 = 5;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[b3]){ // 3
int a4 = 0, b4 = 2, c4 = 5;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[c3]){ // 3
int a4 = 0, b4 = 3, c4 = 5;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
}
if(tmp2 == V[c2]){
int a3 = 1, b3 = 2, c3 = 5;
int tmp3 = AskNext(V[a3], V[b3], V[c3], V[3]);
if(tmp3 == V[a3]){ // 3
int a4 = 0, b4 = 2, c4 = 4;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[b3]){ // 3
int a4 = 0, b4 = 2, c4 = 4;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
if(tmp3 == V[c3]){ // 3
int a4 = 0, b4 = 3, c4 = 4;
int tmp4 = AskMedian(V[a4], V[b4], V[c4]);
Solve();
return ;
}
}
}
return ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |