#include "shuffle.h"
#include <cstring>
#include <vector>
using namespace std;
const int N = 1000, L = 10; /* L = ceil(log2(N)) */
typedef vector<int> vi;
typedef vector<vi> vvi;
int pp[L], xx[N], idx[N * L], xx_[N];
int uu[N], vv[N];
vi solve(int n, int m, int k, int q, int s) {
vi aa(n);
if (s == 3) {
int l = 0, p = 1;
while (p < n)
pp[l++] = p, p *= m;
for (int i = 0; i < n; i++) {
int d = i % m, x = d;
for (int h = 1; h < l; h++) {
int d_ = (i / pp[h] + d) % m;
x += d_ * pp[h];
}
xx[i] = x, idx[x] = i;
}
memset(xx_, 0, n * sizeof *xx_);
for (int h = 0; h < l; h++) {
vvi iii(m);
for (int d = 0; d < m; d++)
iii[d].clear();
for (int i = 0; i < n; i++)
iii[xx[i] / pp[h] % m].push_back(i + 1);
vvi aaa = shuffle(iii);
for (int d = 0; d < m; d++)
for (int g = 0; g < k; g++)
xx_[aaa[d][g] - 1] += d * pp[h];
}
for (int a = 0; a < n; a++)
aa[idx[xx_[a]]] = a + 1;
} else if (s == 2 || s == 4) {
vvi iii(m), aaa;
for (int d = 0; d < m; d++)
iii[d].clear();
for (int d = 0; d < m; d++)
iii[d] = { d * 2 + 1, d * 2 + 2 };
aaa = shuffle(iii);
for (int d = 0; d < m; d++) {
int a = aaa[d][0] - 1, b = aaa[d][1] - 1;
uu[a] = b, uu[b] = a;
}
for (int d = 0; d + 1 < m; d++)
iii[d] = { d * 2 + 2, d * 2 + 3 };
iii[m - 1] = { n, 1 };
aaa = shuffle(iii);
for (int d = 0; d < m; d++) {
int a = aaa[d][0] - 1, b = aaa[d][1] - 1;
vv[a] = b, vv[b] = a;
}
for (int i = 2, j = n - 1; j - i > 3; i++, j--)
iii[i - 2] = { i + 1, j + 1 };
iii[m - 3] = { m, m + 2 }, iii[m - 2] = { m + 1, m + 3 };
iii[m - 1] = { 1, 2 };
aaa = shuffle(iii);
int a_ = -1, b_ = -1;
for (int d = 0; d < m; d++) {
int a = aaa[d][0] - 1, b = aaa[d][1] - 1;
if (uu[a] == b) {
a_ = a, b_ = b;
break;
}
}
for (int i = 1, j = n - 2; j - i > 3; i++, j--)
iii[i - 1] = { i + 1, j + 1 };
iii[m - 3] = { m - 1, m + 1 }, iii[m - 2] = { m, m + 2 };
iii[m - 1] = { n, 1 };
aaa = shuffle(iii);
for (int d = 0; d < m; d++) {
int a = aaa[d][0] - 1, b = aaa[d][1] - 1;
if (vv[a] == b) {
if (b_ == a || b_ == b)
a_ = b_;
break;
}
}
for (int i = 0, a = a_; i < n; i++) {
aa[i] = a + 1;
a = i % 2 == 0 ? uu[a] : vv[a];
}
}
return aa;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |