이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include "messy.h"
using namespace std;
const int N = 128;
vector<int> p;
void build(int l, int r, int n) {
if(l == r) return;
int mid = l + r >> 1;
string s(n, '0');
for(int i = 0; i < l; ++i) s[i] = '1';
for(int i = r + 1; i < n; ++i) s[i] = '1';
for(int i = l; i <= mid; ++i) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
build(l, mid, n);
build(mid + 1, r, n);
}
void rec(int l, int r, vector<int> responsible, int n) {
assert(responsible.size() == r - l + 1);
if(l == r) {
assert(responsible.size() == 1);
p[responsible[0]] = l;
return;
}
int mid = l + r >> 1;
string s(n, '1');
for(auto x: responsible) s[x] = '0';
vector<int> v1, v2;
for(int i = 0; i < n; ++i) {
if(s[i] == '0') {
s[i] = '1';
if(check_element(s)) {
v1.push_back(i);
} else v2.push_back(i);
s[i] = '0';
}
}
rec(l, mid, v1, n);
rec(mid + 1, r, v2, n);
}
std::vector<int> restore_permutation(int n, int w, int r) {
build(0, n - 1, n);
compile_set();
p.assign(n, -1);
vector<int> paiu(n);
iota(paiu.begin(),paiu.end(), 0);
rec(0, n - 1, paiu, n);
return p;
}
컴파일 시 표준 에러 (stderr) 메시지
messy.cpp: In function 'void build(int, int, int)':
messy.cpp:10:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
10 | int mid = l + r >> 1;
| ~~^~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from messy.cpp:1:
messy.cpp: In function 'void rec(int, int, std::vector<int>, int)':
messy.cpp:25:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | assert(responsible.size() == r - l + 1);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
messy.cpp:32:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int mid = l + r >> 1;
| ~~^~~
# | 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... |