이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
string to_string(vector<bool> const& mask) {
string res;
for (bool b : mask)
res.push_back(b ? '1' : '0');
return res;
}
void insert(int l, int r, vector<bool>& mask) {
if (r - l == 1)
return;
int mid = (l + r) >> 1;
for (int i = l; i < mid; i++) {
mask[i] = true;
add_element(to_string(mask));
mask[i] = false;
}
for (int i = mid; i < r; i++)
mask[i] = true;
insert(l, mid, mask);
for (int i = l; i < r; i++)
mask[i] = i < mid;
insert(mid, r, mask);
for (int i = l; i < mid; i++)
mask[i] = false;
}
void solve(int l, int r, vector<bool>& mask, vector<int>& perm) {
if (r - l == 1) {
int ind;
for (int i = 0; i < mask.size(); i++)
if (!mask[i])
ind = i;
perm[ind] = l;
return;
}
vector<int> lft, rgt;
for (int i = 0; i < mask.size(); i++) {
if (!mask[i]) {
mask[i] = true;
(check_element(to_string(mask)) ? lft : rgt).push_back(i);
mask[i] = false;
}
}
int mid = (l + r) >> 1;
for (int i : rgt)
mask[i] = true;
solve(l, mid, mask, perm);
for (int i : lft)
mask[i] = true;
for (int i : rgt)
mask[i] = false;
solve(mid, r, mask, perm);
for (int i : lft)
mask[i] = false;
}
vector<int> restore_permutation(int n, int w, int r) {
vector<bool> mask(n, false);
insert(0, n, mask);
compile_set();
vector<int> perm(n);
solve(0, n, mask, perm);
return perm;
}
컴파일 시 표준 에러 (stderr) 메시지
messy.cpp: In function 'void solve(int, int, std::vector<bool>&, std::vector<int>&)':
messy.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 0; i < mask.size(); i++)
| ~~^~~~~~~~~~~~~
messy.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < mask.size(); i++) {
| ~~^~~~~~~~~~~~~
messy.cpp:37:17: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
37 | perm[ind] = l;
| ^
# | 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... |