# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
158482 | davitmarg | 저울 (IOI15_scales) | C++17 | 3 ms | 376 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.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000000ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
#ifndef death
#include "scales.h"
#endif
#ifdef death
int getHeaviest(int a, int b, int c)
{
cout << "? Heavy " << a << " " << b << " " << c << endl;
int res;
cin >> res;
return res;
}
int getMedian(int a, int b, int c)
{
cout << "? Median " << a << " " << b << " " << c << endl;
int res;
cin >> res;
return res;
}
int getLightest(int a, int b, int c)
{
cout << "? Light " << a << " " << b << " " << c << endl;
int res;
cin >> res;
return res;
}
int getNextLightest(int a, int b, int c, int d)
{
cout << "? Next " << a << " " << b << " " << c << " " << d << endl;
int res;
cin >> res;
return res;
}
void answer(int *a)
{
cout << "! ";
for (int i = 0; i < 6; i++)
cout << a[i] << " ";
cout << endl;
}
#endif
int n = 6;
void init(int T)
{
srand(5498659);
}
void smartSort(vector<int> &x)
{
vector<int> mn, mx, p;
mn.PB(getLightest(x[0], x[1], x[2]));
p.clear();
for (int i = 0; i < x.size(); i++)
if (mn[0] != x[i])
p.PB(x[i]);
mn.PB(getLightest(p[0], p[1], p[2]));
for (int i = 0; i < x.size(); i++)
if (mn[0] != x[i] && mn[1] != x[i])
mx.PB(x[i]);
if (getLightest(mn[0], mn[1], mx[0]) == mn[1])
swap(mn[0], mn[1]);
if (getHeaviest(mx[0], mx[1], mn[0]) == mx[0])
swap(mx[0], mx[1]);
x.clear();
x.PB(mn[0]);
x.PB(mn[1]);
x.PB(mx[0]);
x.PB(mx[1]);
}
void orderCoins()
{
vector<int> ind, l, r, ans;
for (int i = 1; i <= n; i++)
ind.PB(i);
random_shuffle(all(ind));
l.PB(ind[0]);
l.PB(ind[1]);
r.PB(ind[2]);
r.PB(ind[3]);
r.PB(ind[4]);
r.PB(ind[5]);
if (getHeaviest(l[0], r[0], r[1]) == l[0])
swap(l[0], r[0]);
if (getHeaviest(l[1], r[2], r[3]) == l[1])
swap(l[1], r[2]);
smartSort(r);
if (getLightest(l[0], l[1], r.back()) == l[1])
swap(l[0], l[1]);
int p, p1;
p = getNextLightest(r[0], r[1], r[2], l[0]);
p1 = getNextLightest(r[0], r[1], r[2], l[1]);
reverse(all(l));
reverse(all(r));
while (!r.empty())
{
if (r.back() == p)
{
ans.PB(l.back());
l.pop_back();
p = p1;
}
ans.PB(r.back());
r.pop_back();
}
int ANS[6];
for (int i = 0; i < n; i++)
ANS[i] = ans[i];
answer(ANS);
}
#ifdef death
int main()
{
int T;
cin >> T;
init(T);
while (T--)
{
orderCoins();
}
return 0;
}
#endif
/*
1
6 5 2 4 2 6 1 2
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |