# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
144655 | emilem | Zagonetka (COI18_zagonetka) | C++14 | 3092 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.
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
template<typename T>
ostream& operator<<(ostream& ostr, const vector<T>& a)
{
for (int i = 0; i < a.size(); ++i)
ostr << a[i] << ' ';
return ostr;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; ++i)
cin >> p[i];
if (n <= 6)
{
for (int i = 0; i < n; ++i)
p[i] = i + 1;
vector<int> small, large;
do {
cout << "query " << p << endl;
int res;
cin >> res;
if (res && small.empty())
small = p;
if (res)
large = p;
} while (next_permutation(p.begin(), p.end()));
cout << "end\n" << small << '\n' << large << endl;
return 0;
}
else
{
int res;
set<int> possible;
for (int i = 0; i < n; ++i)
possible.insert(i);
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
{
swap(p[i], p[j]);
cout << "query " << p << endl;
cin >> res;
if (res)
{
if (possible.count(i)) possible.erase(i);
if (possible.count(j)) possible.erase(j);
}
swap(p[i], p[j]);
}
vector<int> small(n), large(n);
for (int ii = 0; ii < n; ++ii)
small[ii] = large[ii] = ii + 1;
reverse(large.begin(), large.end());
int i = *possible.begin(), j = *(++possible.begin());
if (possible.size() != 2)
throw;
if (i > j)
throw/*swap(i, j)*/;
if (p[i] > p[j])
{
small[j] = small[i];
if (small[i] == n)
/*throw*/;
++small[i];
for (int k = i + 1; k < j; ++k)
++small[k];
}
else
{
large[j] = large[i];
--large[i];
for (int k = i + 1; k < j; ++k)
--large[k];
}
cout << "end\n" << small << '\n' << large << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |