#include "Memory2_lib.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Solve(int T, int N){
vector <ll> num(N*2,-1);
vector <ll> arr(N*2);
srand(time(0));
for (int z=0;z<N*2;z++){
arr[z] = z;
}
random_shuffle(arr.begin(),arr.end());
ll p=-1,q=-1,r=-1;
while (arr.size() > 4){
if (p == -1){
p = rand()%arr.size();
while (num[arr[p]] != -1 || p==q || p==r){
p = rand()%arr.size();
}
p = arr[p];
}
if (q == -1){
q = rand()%arr.size();
while (num[arr[q]] != -1 || p==q || q==r){
q = rand()%arr.size();
}
q = arr[q];
}
if (r == -1){
r = rand()%arr.size();
while (num[arr[r]] != -1 || r==p || q==r){
r = rand()%arr.size();
}
r = arr[r];
}
ll a = Flip(p,q);
ll b = Flip(p,r);
ll c = Flip(q,r);
if (a == b && b == c && c == a) continue;
if (a == b){
num[p] = a;
for (int z=0;z<arr.size();z++){
if (arr[z] == p){
arr.erase(arr.begin()+z);
break;
}
}
p = -1;
}
else if (b == c){
num[r] = b;
for (int z=0;z<arr.size();z++){
if (arr[z] == r){
arr.erase(arr.begin()+z);
break;
}
}
r = -1;
}
else if (c == a){
num[q] = c;
for (int z=0;z<arr.size();z++){
if (arr[z] == q){
arr.erase(arr.begin()+z);
break;
}
}
q = -1;
}
}
vector <vector<ll>> d(arr.size(),vector<ll>(arr.size()));
for (int z=0;z<arr.size();z++){
for (int x=z+1;x<arr.size();x++){
d[z][x] = Flip(arr[z],arr[x]);
d[x][z] = d[z][x];
}
}
ll s = arr.size();
vector <ll> visited(arr.size(),false);
ll ca = arr.size();
while (ca > 1){
for (int z=0;z<s;z++){
if (visited[z]) continue;
ll first = 0;
ll count = 1;
while (visited[first] || first == z){
first++;
}
for (int x=0;x<s;x++){
if (z == x) continue;
if (visited[x]) continue;
if (d[z][x] == d[z][first])count++;
}
if (count == ca){
num[arr[z]] = d[z][first];
ca--;
visited[z] = true;
break;
}
}
}
ll last;
vector<vector<ll>> ans(N);
for (int z=0;z<N*2;z++){
if (num[z] == -1) {
last = z; continue;
}
ans[num[z]].push_back(z);
}
for (int z=0;z<N;z++){
if (ans[z].size() == 1){
ans[z].push_back(last);
}
Answer(ans[z][0],ans[z][1],z);
}
return;
}
Compilation message
memory2.cpp: In function 'void Solve(int, int)':
memory2.cpp:46:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int z=0;z<arr.size();z++){
~^~~~~~~~~~~
memory2.cpp:56:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int z=0;z<arr.size();z++){
~^~~~~~~~~~~
memory2.cpp:66:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int z=0;z<arr.size();z++){
~^~~~~~~~~~~
memory2.cpp:76:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int z=0;z<arr.size();z++){
~^~~~~~~~~~~
memory2.cpp:77:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int x=z+1;x<arr.size();x++){
~^~~~~~~~~~~
memory2.cpp:106:5: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
ll last;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Wrong Answer[1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Wrong Answer[1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Wrong Answer[1] |
2 |
Halted |
0 ms |
0 KB |
- |