이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <string>
#include <cstring>
#include "messy.h"
using namespace std;
int N;
vector<int> perm;
void rec(int l, int r) {
if (l == r) return;
int mid = (l + r)/2;
for (int i = l; i <= mid; i++) {
string s;
for (int j = 0; j < N; j++) {
if (j < l || j > r || j == i) s.push_back('1');
else s.push_back('0');
}
add_element(s);
}
rec(l, mid);
rec(mid+1, r);
}
void reb(int l, int r, vector<int> &elems) {
if (l == r) {
perm[elems[0]] = l;
return;
}
vector<int> lv, rv;
int pos[128];
memset(pos, 0, sizeof(pos));
for (int i = 0; i < elems.size(); i++) pos[elems[i]] = 1;
for (int i = 0; i < elems.size(); i++) {
string s;
for (int j = 0; j < N; j++) {
if (pos[j] == 0 || j == elems[i]) s.push_back('1');
else s.push_back('0');
}
if (check_element(s)) {
lv.push_back(elems[i]);
} else {
rv.push_back(elems[i]);
}
}
int mid = (l + r) / 2;
reb(l, mid, lv);
reb(mid+1, r, rv);
}
std::vector<int> restore_permutation(int n, int w, int r) {
N = n;
rec(0, n-1);
compile_set();
vector<int> inds;
for (int i = 0; i < N; i++) inds.push_back(i);
for (int i = 0; i < N; i++) perm.push_back(0);
reb(0, n-1, inds);
return perm;
}
컴파일 시 표준 에러 (stderr) 메시지
messy.cpp: In function 'void reb(int, int, std::vector<int>&)':
messy.cpp:33:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < elems.size(); i++) pos[elems[i]] = 1;
~~^~~~~~~~~~~~~~
messy.cpp:34:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < elems.size(); i++) {
~~^~~~~~~~~~~~~~
# | 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... |