This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Challenge: Accepted
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 200005
#define pii pair<int, int>
#define ff first
#define ss second
void genstring(int n, int l, int r) { //[l, r)
if (r - l == 1) return;
string a(n, '0');
for (int i = 0;i < n;i++) {
if (i < l || i >= r) a[i] = '1';
}
int m = (l + r) / 2;
for (int i = l;i < m;i++) {
string b = a;
b[i] = '1';
debug("add", b);
add_element(b);
}
genstring(n, l, m), genstring(n, m, r);
}
void solve(int n, int l, int r, vector<int> cand, vector<int> &ans) {
debug("solve", l, r);
pary(cand.begin(), cand.end());
if (r - l == 1) {
ans[cand[0]] = l;
return;
}
int m = (l + r) / 2;
string a(n, '1');
for (int i:cand) a[i] = '0';
vector<int> lef, rig;
for (int i:cand) {
string b = a;
b[i] = '1';
if (check_element(b)) {
lef.push_back(i);
} else {
rig.push_back(i);
}
}
solve(n, l, m, lef, ans);
solve(n, m, r, rig, ans);
}
vector<int> restore_permutation(int n, int W, int R) {
genstring(n, 0, n);
compile_set();
vector<int> ini(n), ans(n);
for (int i = 0;i < n;i++) ini[i] = i;
solve(n, 0, n, ini, ans);
//pary(ans.begin(), ans.end());
return ans;
}
/*
2 1 3 0
add 1000
add 0100
add 1011
add 1110
0001
0100
1011
1101
*/
Compilation message (stderr)
messy.cpp: In function 'void genstring(int, int, int)':
messy.cpp:13:20: warning: statement has no effect [-Wunused-value]
13 | #define debug(...) 0
| ^
messy.cpp:32:3: note: in expansion of macro 'debug'
32 | debug("add", b);
| ^~~~~
messy.cpp: In function 'void solve(int, int, int, std::vector<int>, std::vector<int>&)':
messy.cpp:13:20: warning: statement has no effect [-Wunused-value]
13 | #define debug(...) 0
| ^
messy.cpp:38:2: note: in expansion of macro 'debug'
38 | debug("solve", l, r);
| ^~~~~
messy.cpp:14:19: warning: statement has no effect [-Wunused-value]
14 | #define pary(...) 0
| ^
messy.cpp:39:2: note: in expansion of macro 'pary'
39 | pary(cand.begin(), cand.end());
| ^~~~
# | 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... |