# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
255762 | IgorI | Xylophone (JOI18_xylophone) | C++17 | 0 ms | 0 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 <dist.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
int n;
int okay(vector<int> q)
{
int pos1 = 0, posn = 0;
vector<int> cnt(n + 1);
for (int i = 1; i <= n; i++)
{
if (q[i] < 1 || q[i] > n) return 0;
cnt[q[i]]++;
if (cnt[q[i]] == 2) return 0;
if (q[i] == 1) pos1 = i;
if (q[i] == n) posn = i;
}
return pos1 < posn;
}
void solve(int n0)
{
n = n0;
vector<int> a(n), b(n);
for (int i = 1; i + 1 <= n; i++)
{
a[i] = query(i, i + 1);
}
for (int i = 1; i + 2 <= n; i++)
{
b[i] = query(i, i + 2);
}
vector<int> dir(n);
dir[1] = 1;
for (int i = 1; i + 2 <= n; i++)
{
if (b[i] == a[i] + a[i + 1]) dir[i + 1] = dir[i];
else dir[i + 1] = dir[i] * (-1);
}
vector<vector<int> > ans;
for (int i = 1; i <= n; i++)
{
vector<int> q(n + 1);
q[1] = i;
q[2] = dir[1] * a[1] + q[1];
for (int j = 3; j <= n; j++)
{
q[j] = q[j - 1] + dir[j - 1] * a[j - 1];
}
if (okay(q)) ans.push_back(q);
}
for (int i = 1; i < n; i++) dir[i] *= -1;
for (int i = 1; i <= n; i++)
{
vector<int> q(n + 1);
q[1] = i;
q[2] = dir[1] * a[1] + q[1];
for (int j = 3; j <= n; j++)
{
q[j] = q[j - 1] + dir[j - 1] * a[j - 1];
}
if (okay(q)) ans.push_back(q);
}
for (auto e : ans)
{
for (int i = 1; i <= n; i++)
{
answer(i, e[i]);
}
}
}