이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "messy.h"
#include<bits/stdc++.h>
using namespace std;
string s;
vector<int> pos[900], perm, ans;
void init(int n,int l,int r) {
if(l==r) return ;
int mid = (l+r)/2;
for(int i=0;i<n;i++) s[i] = '1';
for(int i=l;i<=r;i++) s[i] = '0';
for(int i=l;i<=mid;i++) {
s[i] = '1';
// cout << "add_element: " << s << endl;
add_element(s);
s[i] = '0';
}
init(n,l,mid); init(n,mid+1,r);
}
void query(int n,int now,int l,int r) {
// printf("query %d %d\n",l,r);
if(l==r) {
perm[l] = pos[now][0];
return ;
}
int mid = (l+r)/2;
for(int i=0;i<n;i++) s[i] = '1';
for(int i=0;i<pos[now].size();i++) s[pos[now][i]] = '0';
for(int i=0;i<pos[now].size();i++) {
int x = pos[now][i];
s[x] = '1';
int temp = check_element(s);
// cout << "check_element: " << s << " = " << temp << endl;
s[x] = '0';
if(temp==1) pos[now<<1].push_back(x);
else pos[now<<1|1].push_back(x);
}
query(n,now<<1,l,mid); query(n,now<<1|1,mid+1,r);
}
std::vector<int> restore_permutation(int n, int w, int r) {
for(int i=0;i<n;i++) s += "0";
init(n,0,n-1);
compile_set();
for(int i=0;i<n;i++) perm.push_back(-1), pos[1].push_back(i);
query(n,1,0,n-1);
for(int i=0;i<n;i++) ans.push_back(-1);
for(int i=0;i<n;i++) ans[perm[i]] = i;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
messy.cpp: In function 'void query(int, int, int, int)':
messy.cpp:30:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<pos[now].size();i++) s[pos[now][i]] = '0';
~^~~~~~~~~~~~~~~~
messy.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<pos[now].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... |