# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
427145 | InternetPerson10 | Unscrambling a Messy Bug (IOI16_messy) | C++17 | 5 ms | 588 KiB |
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 <vector>
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
bool arr[128];
vector<int> ans, ans2;
vector<vector<int>> nums;
string arrTo() {
string s = "";
for(int i = 0; i < ans.size(); i++) {
s += (arr[i] ? "1" : "0");
}
// cout << s << '\n';
return s;
}
vector<int> restore_permutation(int n, int w, int r) {
int g = 0, x = 1;
while(x != n) {
g++; x *= 2;
}
ans.resize(n); ans2.resize(n);
for(int i = 0; i < n; i++) {
arr[i] ^= true;
for(int j = 2; j < g; j++) {
int k = (i | ((1 << j) - 1)) - ((1 << j) - 1);
for(int m = 0; m < (1 << j); m++) {
arr[k+m] ^= true; // flips all in the 2^j block
}
if(i & (1 << (j-1))) add_element(arrTo());
for(int m = 0; m < (1 << j); m++) {
arr[k+m] ^= true;
}
}
if(i >= n/2) {
for(int j = 0; j < n; j++) arr[j] ^= true;
// cout << "big: ";
add_element(arrTo());
for(int j = 0; j < n; j++) arr[j] ^= true;
}
if(i%2 == 1) {
// cout << "odd: ";
add_element(arrTo());
}
arr[i] ^= true;
}
// cout << "Compiled set!\n";
compile_set();
for(int i = 0; i < n; i++) { // determine odd/even
arr[i] ^= true;
if(check_element(arrTo())) ans[i]++;
arr[i] ^= true;
}
for(int i = 0; i < n; i++) arr[i] ^= true;
nums.resize(2);
for(int i = 0; i < n; i++) { // determine wrt n/2
arr[i] ^= true;
if(check_element(arrTo())) {
nums[1].push_back(i);
ans[i] += (1 << (g-1));
}
else nums[0].push_back(i);
arr[i] ^= true;
}
for(int i = 0; i < n; i++) arr[i] ^= true;
int curr = 0; // current process vector
int curg = 0; // bit currently being processed
while(curr != nums.size()) {
int k = 1;
curg = 0;
int ne = nums.size();
while(k != nums[curr].size()) {
curg++; k *= 2;
}
if(curg > 2) {
nums.push_back(vector<int>());
nums.push_back(vector<int>());
}
for(int i = 0; i < nums[curr].size(); i++) {
arr[nums[curr][i]] ^= true;
}
for(int i = 0; i < nums[curr].size(); i++) {
// cout << nums[curr][i] << ' ';
arr[nums[curr][i]] ^= true;
if(check_element(arrTo())) {
ans[nums[curr][i]] += (1 << (curg-1));
if(curg > 2) nums[ne].push_back(nums[curr][i]);
}
else if(curg > 2) nums[ne+1].push_back(nums[curr][i]);
arr[nums[curr][i]] ^= true;
}
// cout << '\n';
for(int i = 0; i < nums[curr].size(); i++) {
arr[nums[curr][i]] ^= true;
}
curr++;
}
// for(int i = 0; i < n; i++) ans2[ans[i]] = i;
return ans;
}
Compilation message (stderr)
# | 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... |