#include "permutation.h"
#include <cstring>
#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 max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
char used[N];
int check(int *pp, int n, int m) {
int p = 0;
for (int i = 0; i < m; i++)
p = min(p, pp[i]);
memset(used, 0, n * sizeof *used);
for (int i = 0; i < m; i++) {
if (pp[i] - p >= n || used[pp[i] - p])
return 0;
used[pp[i] - p] = 1;
}
return 1;
}
int rr[N], dd[N], ppp[N + 1][N], ppp_[N + 1][N], m, m_;
void solve(int n) {
for (int i = 0; i < n; i++)
rr[i] = i;
for (int i = 0; i < n; i++) {
int j = rand_() % (i + 1), tmp;
tmp = rr[i], rr[i] = rr[j], rr[j] = tmp;
}
vi ii(n);
for (int i = 0; i < n; i++) {
for (int h = 0; h < n; h++)
ii[h] = rr[(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), qq(n);
pp[0] = 0, pp[1] = dd[1];
for (int i = 2; i < n; i++) {
int m = 0;
for (int j = 0; j < i; j++)
ppp[m][j] = pp[j];
m++;
while (i < n) {
m_ = 0;
for (int h = 0; h < m; h++) {
memcpy(ppp_[m_], ppp[h], i * sizeof *ppp[h]), ppp_[m_][i] = ppp[h][i - 1] + dd[i];
if (check(ppp_[m_], n, i + 1))
m_++;
if (m_ > n)
break;
memcpy(ppp_[m_], ppp[h], i * sizeof *ppp[h]), ppp_[m_][i] = ppp[h][i - 1] - dd[i];
if (check(ppp_[m_], n, i + 1))
m_++;
if (m_ > n)
break;
}
memset(used, 0, n * sizeof *used);
for (int h = 0; h < m_; h++) {
int p = abs_(ppp_[h][i]);
if (used[p])
goto out;
used[p] = 1;
}
m = m_;
for (int h = 0; h < m_; h++)
memcpy(ppp[h], ppp_[h], (i + 1) * sizeof *ppp_[h]);
i++;
}
out:
if (i == n) {
for (int h = 0; h < m; h++)
if (abs_(ppp[h][0] - ppp[h][n - 1]) == dd[0]) {
for (int j = 0; j < n; j++)
pp[j] = ppp[h][j];
break;
}
} else {
i--;
for (int h = 0; h < n; h++)
ii[h] = rr[h < i ? i - 1 - h : h] + 1;
int p = query(ii) - (sum - dd[0]) + dd[i];
for (int h = 0; h < m; h++)
if (abs_(ppp[h][i]) == p) {
for (int j = 0; j <= i; j++)
pp[j] = ppp[h][j];
break;
}
}
}
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;
for (int i = 0; i < n; i++)
qq[rr[i]] = pp[i];
for (int i = 0; i < n; i++)
pp[i] = qq[i];
answer(pp);
}
Compilation message
stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | fscanf(stdin, "%d", &x);
| ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | fscanf(stdin, "%d", &N);
| ~~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
436 KB |
Partially correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Partially correct |
0 ms |
436 KB |
Partially correct |
4 |
Correct |
0 ms |
428 KB |
Output is correct |
5 |
Correct |
0 ms |
428 KB |
Output is correct |
6 |
Partially correct |
0 ms |
432 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
436 KB |
Partially correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Partially correct |
0 ms |
436 KB |
Partially correct |
4 |
Correct |
0 ms |
428 KB |
Output is correct |
5 |
Correct |
0 ms |
428 KB |
Output is correct |
6 |
Partially correct |
0 ms |
432 KB |
Partially correct |
7 |
Partially correct |
1 ms |
436 KB |
Partially correct |
8 |
Partially correct |
1 ms |
428 KB |
Partially correct |
9 |
Partially correct |
1 ms |
432 KB |
Partially correct |
10 |
Partially correct |
1 ms |
428 KB |
Partially correct |
11 |
Partially correct |
1 ms |
436 KB |
Partially correct |
12 |
Partially correct |
1 ms |
432 KB |
Partially correct |
13 |
Partially correct |
0 ms |
436 KB |
Partially correct |
14 |
Partially correct |
1 ms |
628 KB |
Partially correct |
15 |
Partially correct |
1 ms |
432 KB |
Partially correct |
16 |
Partially correct |
1 ms |
428 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
436 KB |
Partially correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Partially correct |
0 ms |
436 KB |
Partially correct |
4 |
Correct |
0 ms |
428 KB |
Output is correct |
5 |
Correct |
0 ms |
428 KB |
Output is correct |
6 |
Partially correct |
0 ms |
432 KB |
Partially correct |
7 |
Partially correct |
1 ms |
436 KB |
Partially correct |
8 |
Partially correct |
1 ms |
428 KB |
Partially correct |
9 |
Partially correct |
1 ms |
432 KB |
Partially correct |
10 |
Partially correct |
1 ms |
428 KB |
Partially correct |
11 |
Partially correct |
1 ms |
436 KB |
Partially correct |
12 |
Partially correct |
1 ms |
432 KB |
Partially correct |
13 |
Partially correct |
0 ms |
436 KB |
Partially correct |
14 |
Partially correct |
1 ms |
628 KB |
Partially correct |
15 |
Partially correct |
1 ms |
432 KB |
Partially correct |
16 |
Partially correct |
1 ms |
428 KB |
Partially correct |
17 |
Partially correct |
6 ms |
432 KB |
Partially correct |
18 |
Partially correct |
6 ms |
680 KB |
Partially correct |
19 |
Partially correct |
6 ms |
680 KB |
Partially correct |
20 |
Partially correct |
6 ms |
432 KB |
Partially correct |
21 |
Partially correct |
8 ms |
404 KB |
Partially correct |
22 |
Partially correct |
6 ms |
428 KB |
Partially correct |
23 |
Partially correct |
7 ms |
432 KB |
Partially correct |
24 |
Partially correct |
6 ms |
688 KB |
Partially correct |
25 |
Partially correct |
6 ms |
432 KB |
Partially correct |
26 |
Partially correct |
6 ms |
688 KB |
Partially correct |