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 "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());
while (arr.size() > 4){
ll p,q,r;
p = rand()%arr.size();
q = rand()%arr.size();
r = rand()%arr.size();
while (num[p] != -1 || num[q] != -1 || num[r] != -1 || p==q || p==r || q==r){
p = rand()%arr.size();
q = rand()%arr.size();
r = rand()%arr.size();
}
ll a = Flip(arr[p],arr[q]);
ll b = Flip(arr[p],arr[r]);
ll c = Flip(arr[q],arr[r]);
if (a == b && b == c && c == a) continue;
if (a == b){
num[arr[p]] = a;
arr.erase(arr.begin()+p);
}
else if (b == c){
num[arr[r]] = b;
arr.erase(arr.begin()+r);
}
else if (c == a){
num[arr[q]] = c;
arr.erase(arr.begin()+q);
}
}
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 (stderr)
memory2.cpp: In function 'void Solve(int, int)':
memory2.cpp:42:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int z=0;z<arr.size();z++){
~^~~~~~~~~~~
memory2.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int x=z+1;x<arr.size();x++){
~^~~~~~~~~~~
memory2.cpp:72:5: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
ll last;
^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |