Submission #1193726

#TimeUsernameProblemLanguageResultExecution timeMemory
1193726tkm_algorithmsUnscrambling a Messy Bug (IOI16_messy)C++20
100 / 100
1 ms584 KiB
/**
*    In the name of Allah
*    We are nothing and you're everything
**/
#include <bits/stdc++.h>
#include "messy.h"

using namespace std;
using ll = long long;

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

//const ll inf = 1e18;

int n, occ[128];

void solve(int l, int r) {
	if (l == r)return;
	string s;
	for (int j = 0; j < n; ++j)s += '0';
	
	for (int j = l; j <= r; ++j)s[j] = '1';
	
	int m = l+r>>1;
	for (int j = m+1; j <= r; ++j) {
		s[j] = '0';
		add_element(s);
		s[j] = '1';
	}
	
	solve(l, m); solve(m+1, r);
}

void solve2(int l, int r, vector<int> c) {
	if (l == r) {
		occ[c[0]] = l;
		return;
	}
	
	int m = l+r>>1;
	
	string s;
	for (int i = 0; i < n; ++i)s += '0';
	
	for (auto &i: c)s[i] = '1';
	
	vector<int> lx, rx;
	for (auto &j: c) {
		s[j] = '0';
		if (check_element(s))rx.push_back(j);
		else lx.push_back(j);
		s[j] = '1';
	}
	
	solve2(l, m, lx); solve2(m+1, r, rx);
}

vector<int> restore_permutation(int N, int W, int R) {
	n = N;
	solve(0, n-1);
	compile_set();
	vector<int> v;
	for (int i = 0; i < n; ++i)v.push_back(i);
	solve2(0, n-1, v);
	vector<int> dap;
	for (int i = 0; i < n; ++i)dap.push_back(occ[i]);
	return dap;
}

Compilation message (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...