# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685443 | annie2018 | Secret Permutation (RMI19_permutation) | C++17 | 3610 ms | 428 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 <bits/stdc++.h>
#include "permutation.h"
using namespace std;
int n;
vector <int> ans, v, a, q;
vector <bool> used;
void get (int x)
{
used[a[x]] = 1;
if (x == n && abs(a[1] - a[x]) == q[n])
{
vector <int> fin(n + 1), ret;
for(int i = 1;i <= n; i++)
{
fin[v[i - 1]] = a[i];
}
for(int i = 1; i <= n; i++)
{
ret.push_back(fin[i]);
}
answer(ret);
exit(0);
}
else
{
int one = a[x] - q[x], two = a[x] + q[x];
if (one > 0 && one <= n && !used[one])
{
a[x + 1] = one;
get(x + 1);
}
if (two > 0 && two <= n && !used[two])
{
a[x + 1] = two;
get(x + 1);
}
}
used[a[x]] = 0;
a[x] = 0;
}
void solve(int nn)
{
n = nn;
srand(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 1; i <= n; i++)
v.push_back(i);
random_shuffle(v.begin(), v.end());
//vector <int> q(n);
q.resize(n + 1);
for(int i = 1; i <= n; i++)
{
rotate(v.begin(), v.begin() + 1, v.end());
q[i] = query(v);
}
rotate(v.begin(), v.begin() + 1, v.end());
int sum = 0;
for(int i = 1; i <= n; i++)
sum += q[i];
sum /= (n - 1);
for(int i = 1; i <= n; i++)
q[i] = (sum - q[i]);
q.push_back(q[1]);
for(int i = 1; i <= n; i++)
q[i] = q[i + 1];
/*for (int i = 0; i < v.size(); i++)
cout << v[i] << ' ';
cout << "\n";
for (int i = 0; i < q.size(); i++)
cout << q[i] << ' ';
cout << "\n";*/
//get(q, n);
for (int i = 1; i <= n; i++)
{
a.assign(n + 1, 0);
a[1] = i;
used.assign(n + 1, 0);
get(1);
}
//answer(ans);
}
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... |