#include "shuffle.h"
#include <bits/stdc++.h>
#define pb push_back
#ifdef ONLINE_JUDGE
#define cout cerr
#endif
using namespace std;
using v2d = vector<vector<int>>;
using v1d = vector<int>;
int N, B, K;
v2d self_shuffle(v2d query){
for(auto& q : query){
for(auto& i : q){
i = (i % N + N) % N + 1;
}
}
return shuffle(query);
}
void norm(v2d& v2){
for(auto& v : v2){
sort(v.begin(), v.end());
}
sort(v2.begin(), v2.end());
}
const int MAXN = 1e4 + 11;
vector<int> G[MAXN];
deque<int> val;
bool vis[MAXN];
int c[MAXN];
void dfs(int v, int pa = -1){
vis[v] = true; val.push_back(v);
for(auto i : G[v]){
if(i != pa && !vis[i]) c[i] = c[v] ^ 1, dfs(i, v);
}
}
bool is_adj(int u, int v){
for(auto i : G[u]){
if(i == v) return true;
}
return false;
}
int adj_exc(int u, int v){
for(auto i : G[u]){
if(i != v) return i;
}
return -1;
}
ostream& operator<< (ostream& out, v2d v){
out << "Vec2d: " << endl;
for(auto i : v){
for(auto ii : i){
out << ii << ' ';
}
out << endl;
}
return out << endl;
}
ostream& operator<< (ostream& out, v1d v){
out << "Vec1d: " << endl;
for(auto i : v){
out << i << ' ';
}
return out << endl;
}
vector<int> solve(int N, int B, int K, int Q, int ST) {
::N = N, ::B = B, ::K = K;
vector<int> ans(N);
if(K == 2){
v2d query, res;
for(int i = 0; i < B; i++){
query.push_back({i * 2, i * 2 + 1});
}
res = self_shuffle(query);
for(auto p : res){
G[p[0]].push_back(p[1]);
G[p[1]].push_back(p[0]);
}
query.clear();
for(int i = 0; i < B; i++){
query.push_back({i * 2, i * 2 - 1});
}
res = self_shuffle(query);
for(auto p : res){
G[p[0]].push_back(p[1]);
G[p[1]].push_back(p[0]);
}
dfs(1);
query.clear();
query.push_back({0, 2});
query.push_back({1, 3});
for(int i = 2; i < B; i++){
query.push_back({i * 2, i * 2 + 1});
}
v2d v1 = self_shuffle(query);
query.clear();
query.push_back({0, 2});
query.push_back({3, 5});
query.push_back({1, 4});
for(int i = 3; i < B; i++){
query.push_back({i * 2, i * 2 + 1});
}
v2d v2 = self_shuffle(query);
norm(v1), norm(v2);
v2d s1, s2;
for(int i = 0; i < B; i++){
if(c[v1[i][0]] == c[v1[i][1]]) s1.push_back(v1[i]);
if(c[v2[i][0]] == c[v2[i][1]]) s2.push_back(v2[i]);
}
v1d a02;
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
if(s1[i] == s2[j]){
a02 = s1[i];
if(s1[!i][0] == s2[!j][0] || s1[!i][1] == s2[!j][0]) ans[3] = s2[!j][0];
else ans[3] = s2[!j][1];
}
}
}
if(is_adj(a02[0], ans[3])) ans[2] = a02[0], ans[0] = a02[1];
else ans[2] = a02[1], ans[0] = a02[0];
ans[1] = adj_exc(ans[2], ans[3]);
for(int i = 4; i < N; i++){
ans[i] = adj_exc(ans[i - 1], ans[i - 2]);
}
return ans;
}
if(B == 2){
v2d query, res;
v2d r1, r2, r3;
{
v1d v1, v2;
for(int i = 0; i < K; i++){
v1.push_back(i);
v2.push_back(i + K);
}
query = {v1, v2};
r1 = self_shuffle(query);
}
{
v1d v1, v2;
v1.push_back(0); v2.push_back(K);
for(int i = 1; i < K; i++){
v1.push_back(i + K);
v2.push_back(i);
}
query = {v1, v2};
r2 = self_shuffle(query);
}
{
v1d v1, v2;
v1.push_back(0); v1.push_back(K);
for(int i = 1; i < K - 1; i++){
v1.push_back(i);
}
v2.push_back(K - 1);
for(int i = 1; i < K; i++){
v2.push_back(i + K);
}
query = {v1, v2};
r3 = self_shuffle(query);
}
for(int i = 0; i < B; i++){
for(int j = 0; j < K; j++){
c[r1[i][j]] = i;
}
}
v1d a03;
for(int i = 0; i < B; i++){
int cnt[2] = {0, 0};
for(int j = 0; j < K; j++){
cnt[c[r2[i][j]]]++;
}
int eq1 = cnt[0] == 1 ? 0 : 1;
for(int j = 0; j < K; j++){
if(c[r2[i][j]] == eq1){
a03.push_back(r2[i][j]);
}
}
}
for(int i = 0; i < B; i++){
bool ex = false, colour = false;
for(int j = 0; j < K; j++){
if(r3[i][j] == a03[0] || r3[i][j] == a03[1]) ex = true;
else colour = c[r3[i][j]];
}
if(ex){
if(colour == c[a03[0]]) ans[0] = a03[0], ans[K] = a03[1];
else ans[0] = a03[1], ans[K] = a03[0];
}
}
v1d id(N + 1);
for(int b = 0; b < 9; b++){
v1d v[2]; v[0].pb(0); v[1].pb(K);
for(int j = 1; j < K; j++){
bool ok = j & (1 << b);
v[0].push_back(j + ok * K);
v[1].push_back(j + (!ok) * K);
}
v2d query = {v[0], v[1]};
v2d res = self_shuffle(query);
bool in_0 = false; for(auto i : res[0]) if(i == ans[0]) in_0 = true;
if(!in_0) swap(res[0], res[1]);
for(auto i : res[1]) id[i] |= (1 << b);
}
for(int i = 1; i <= N; i++){
if(c[i] == c[ans[0]]){
ans[id[i]] = i;
}else{
ans[K + (id[i] ^ 511)] = i;
}
}
return ans;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
552 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |