#include <vector>
#include <iostream>
#include "messy.h"
using namespace std;
std::vector<int> restore_permutation(int n, int w, int r) {
vector<vector<string>> nums = {{"10000000", "01000000", "00100000", "00010000"},
{"10001000", "01000100", "00100010", "00010001"},
{"01111011", "10111101", "11011110", "11100111"}};
for (auto &i : nums) {
for (auto &j : i) add_element(j);
}
compile_set();
vector<vector<int>> checks(3, vector<int>(4));
vector<vector<int>> changes(3);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 4; ++j) {
checks[i][j] = check_element(nums[i][j]);
if (!checks[i][j]) changes[i].push_back(j);
}
}
vector<int> res(n);
for (int i = 0; i < n; ++i) res[i] = i;
// for (auto &i : checks) {
// cout << "START: ";
// for (auto &j : i) cout << j << ' ';
// cout << '\n';
// }
// for (auto &i : changes) {
// cout << "START2: ";
// for (auto &j : i) cout << j << ' ';
// cout << '\n';
// }
if (!changes[0].empty()) {
int change = changes[0][0];
if (checks[1][change]) {
swap(res[change], res[change + 4]);
return res;
} else {
int change2 = -1;
for (int i = 0; i < 4; ++i) {
if (i != change && (!checks[1][i])) {
change2 = i + 4;
break;
}
}
// cout << change << ' ' << change2 << '\n';
swap(res[change], res[change2]);
return res;
}
} else {
if (changes[1].empty()) return res;
vector<vector<int>> counts(n, vector<int>(n, 0));
int change1 = changes[1][0], change2 = changes[1][1];
++counts[change1][change2];
++counts[change1 + 4][change2 + 4];
change1 = changes[2][0], change2 = changes[2][1];
++counts[change1][change2];
int val1 = (change1 + 1) % 4 + 4, val2 = (change2 + 1) % 4 + 4;
++counts[min(val1, val2)][max(val1, val2)];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (counts[i][j] == 2) {
swap(res[i], res[j]);
return res;
}
}
}
}
}
Compilation message (stderr)
messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
79 | }
| ^
messy.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
messy_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |