# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
275753 | hamerin | Paint By Numbers (IOI16_paint) | C++17 | 0 ms | 0 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 "messy.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i64 = long long;
using d64 = long double;
using pi = pair<int, int>;
using pli = pair<i64, i64>;
using ti = tuple<int, int, int>;
using tli = tuple<i64, i64, i64>;
#define iterall(cont) cont.begin(), cont.end()
#define prec(n) setprecision(n) << fixed
int N;
void add(int s, int e) {
if (s == e - 1) return;
string str(N, '1');
for (int i = s; i < e; i++) {
str[i] = '0';
}
int m = (s + e) >> 1;
for (int i = m; i < e; i++) {
str[i] = '1';
add_element(str);
str[i] = '0';
}
add(s, m);
add(m, e);
}
vector<int> per;
void check(int s, int e) {
int m = (s + e) >> 1;
if (s == e - 1) return;
if (e - s == N) {
string str(N, '0');
for (int i = 0; i < N; i++) {
str[i] = '1';
if (check_element(str)) per[i] = m;
str[i] = '0';
}
} else {
string str(N, '1');
vector<int> tar;
for (int i = 0; i < N; i++) {
if (per[i] == s) tar.emplace_back(i);
}
for (auto i : tar) str[i] = '0';
for (int i = 0; i < e - s; i++) {
str[tar[i]] = '1';
if (check_element(str)) per[tar[i]] = m;
str[tar[i]] = '0';
}
}
check(s, m);
check(m, e);
}
vector<int> restore_permutation(int n, int w, int r) {
N = n;
per.resize(N);
add(0, n);
compile_set();
check(0, n);
return per;
}