# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
871345 | rainboy | Secret Permutation (RMI19_permutation) | C++17 | 13 ms | 600 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 "permutation.h"
#include <vector>
using namespace std;
typedef vector<int> vi;
const int N = 256;
int abs_(int a) { return a > 0 ? a : -a; }
int min(int a, int b) { return a < b ? a : b; }
int dd[N];
void solve(int n) {
vi ii(n);
for (int i = 0; i < n; i++) {
for (int h = 0; h < n; h++)
ii[h] = (i + h) % n + 1;
dd[i] = query(ii);
}
int sum = 0;
for (int i = 0; i < n; i++)
sum += dd[i];
sum /= (n - 1);
for (int i = 0; i < n; i++)
dd[i] = sum - dd[i];
vi pp(n);
pp[0] = 0, pp[1] = dd[1];
for (int i = 2; i < n; i++) {
for (int h = 0; h < n; h++)
ii[h] = (h < i ? i - 1 - h : h) + 1;
pp[i] = query(ii) - (sum - dd[0]) + dd[i];
if (abs_(pp[i] - pp[i - 1]) != dd[i])
pp[i] = -pp[i];
}
int p = 0;
for (int i = 0; i < n; i++)
p = min(p, pp[i]);
for (int i = 0; i < n; i++)
pp[i] -= p - 1;
answer(pp);
}
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... |