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 <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y){
return uniform_int_distribution<int>(x, y)(rng);
}
int Flip(int I, int J);
void Answer(int I, int J, int X);
void out(int i, int j, int k) {
if (i > j) swap(i, j);
Answer(i, j, k);
}
void Solve(int t, int n){
vector<int> v;
for (int i = 0; i < (n << 1); i++) v.push_back(i);
while (!v.empty()) {
vector<vector<int>> p(n);
int ptr = v[rnd(0, v.size()-1)], it;
for (int i = 0; i < v.size(); i++) if (v[i] != ptr) p[Flip(ptr, v[i])].push_back(v[i]);
for (int i = 0; i < n; i++) {
if (p[i].size() == 2) {
v.erase(find(v.begin(), v.end(), p[i][0]));
v.erase(find(v.begin(), v.end(), p[i][1]));
out(p[i][0], p[i][1], i);
} else if (p[i].size() & 1) it = i;
}
if (v.size() == 2) {
out(v[0], v[1], it);
return;
}
}
}
Compilation message (stderr)
memory2.cpp: In function 'void Solve(int, int)':
memory2.cpp:19:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < v.size(); i++) if (v[i] != ptr) p[Flip(ptr, v[i])].push_back(v[i]);
| ~~^~~~~~~~~~
memory2.cpp:11:11: warning: 'it' may be used uninitialized in this function [-Wmaybe-uninitialized]
11 | Answer(i, j, k);
| ~~~~~~^~~~~~~~~
memory2.cpp:18:42: note: 'it' was declared here
18 | int ptr = v[rnd(0, v.size()-1)], it;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |