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"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define ffor(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define fford(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define rep(i, n) ffor(i, 0, n)
#define forin(x, a) for (auto &x: a)
#define all(a) a.begin(), a.end()
std::vector<int> restore_permutation(int n, int w, int r) {
string el(n, '0');
rep(i, n - 3) {
el[i] = '1';
ffor(j, i + 1, n) {
el[j] = '1';
add_element(el);
el[j] = '0';
}
}
el[0] = '0';
el[n - 3] = '1';
add_element(el);
el[n - 2] = '1';
add_element(el);
compile_set();
vii res(n);
int res2;
set<int> rem;
rep(i, n) {
rem.emplace(i);
}
int cnt = 0;
string curr(n, '0');
while (rem.size() > 3) {
vii cand;
forin(x, rem) {
cand.emplace_back(x);
}
bool found = false;
for (int i = 0; i < cand.size() - 2; i += 2) {
curr[cand[i]] = '1';
curr[cand[i + 1]] = '1';
if (check_element(curr)) {
curr[cand[i + 1]] = '0';
curr[cand[i + 2]] = '1';
if (check_element(curr)) {
if (!cnt) {
res2 = cand[i];
}
res[cand[i]] = cnt++;
rem.erase(cand[i]);
found = true;
curr[cand[i + 2]] = '0';
break;
} else {
if (!cnt) {
res2 = cand[i + 1];
}
res[cand[i + 1]] = cnt++;
rem.erase(cand[i + 1]);
found = true;
curr[cand[i]] = '0';
curr[cand[i + 1]] = '1';
curr[cand[i + 2]] = '0';
break;
}
}
curr[cand[i]] = curr[cand[i + 1]] = '0';
}
if (!found) {
if (cand.size() % 2) {
curr[cand.back()] = '1';
if (!cnt) {
res2 = cand.back();
}
res[cand.back()] = cnt++;
rem.erase(cand.back());
} else {
curr[cand[0]] = '1';
curr[cand.back()] = '1';
if (check_element(curr)) {
curr[cand[0]] = '0';
if (!cnt) {
res2 = cand.back();
}
res[cand.back()] = cnt++;
rem.erase(cand.back());
} else {
curr[cand[0]] = '0';
curr[cand.back()] = '0';
curr[cand[cand.size() - 2]] = '1';
if (!cnt) {
res2 = cand[cand.size() - 2];
}
res[cand[cand.size() - 2]] = cnt++;
rem.erase(cand[cand.size() - 2]);
}
}
}
}
curr[res2] = '0';
while (rem.size() > 1) {
forin(x, rem) {
curr[x] = '1';
if (check_element(curr)) {
res[x] = cnt++;
rem.erase(x);
break;
}
curr[x] = '0';
}
}
res[*rem.begin()] = cnt;
return res;
}
Compilation message (stderr)
messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 0; i < cand.size() - 2; i += 2) {
| ~~^~~~~~~~~~~~~~~~~
messy.cpp:116:14: warning: 'res2' may be used uninitialized in this function [-Wmaybe-uninitialized]
116 | curr[res2] = '0';
| ^
# | 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... |