이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> ans;
string defaultStr;
void add(vector <int> ids) {
string tmp = defaultStr;
for (auto a : ids) tmp[a] = '1';
add_element(tmp);
}
int val;
bool check(vector <int> ids) {
string tmp = defaultStr;
for (auto a : ids) tmp[a] = '1';
val = check_element(tmp);
// cout << "ask " << tmp << ": " << val << '\n';
return val;
}
void init(int st, int end, vector<int>&use) {
if (st == end) return;
int mid = (st+end)/2;
for (int i = mid+1; i <= end; i++) {
vector <int> tmp = use;
tmp.push_back(i);
add(tmp);
}
//lowHalf
for (int i = st; i <= mid; i++) {
use.push_back(i);
}
init(mid+1, end, use);
for (int i = st; i <= mid; i++) {
use.pop_back();
}
//upperHalf
for (int i = mid+1; i <= end; i++) {
use.push_back(i);
}
init(st, mid, use);
for (int i = mid+1; i <= end; i++) {
use.pop_back();
}
}
void solve(int st, int end, vector <int>&use) {
// cout << st << ' ' << end << ": ";
// for (auto el : use) cout << el << ' ';
// cout << '\n';
vector <bool> seen(n, 0);
for (auto el : use) seen[el] = 1;
if (st == end) {
val = 0;
for (int i = 0; i < n; i++) {
if (!seen[i]) val = i;
}
// cout << "ANS: " << val << ": " << st << '\n';
ans[val] = st;
return;
}
int mid = (st+end)/2;
vector <int> lower, upper;
for (int i = 0; i < n; i++) {
if (seen[i]) continue;
vector <int> tmp = use;
tmp.push_back(i);
bool cur = check(tmp);
if (cur) upper.push_back(i);
else lower.push_back(i);
}
// cout << "lower: ";
// for (auto el : lower) cout << el << ' ';
// cout << '\n';
// cout << "upper: ";
// for (auto el : upper) cout << el << ' ';
// cout << '\n';
//lowHalf
for (int i = 0; i < lower.size(); i++) {
use.push_back(lower[i]);
}
solve(mid+1, end, use);
for (int i = 0; i < lower.size(); i++) {
use.pop_back();
}
//upperHalf
for (int i = 0; i < upper.size(); i++) {
use.push_back(upper[i]);
}
solve(st, mid, use);
for (int i = 0; i < upper.size(); i++) {
use.pop_back();
}
}
vector<int> restore_permutation(int n1, int w, int r) {
n = n1;
for (int i = 0; i < n; i++) ans.push_back(-i);
for (int i = 0; i < n; i++) defaultStr.push_back('0');
vector <int> use;
init(0, n-1, use);
compile_set();
// cout << "DONE\n";
// set <int> posVals;
// for (int i = 0; i < n; i++) posVals.insert(i);
solve(0, n-1, use);
// vector <int> test1 = {2, 1, 3, 0};
// check_element("0");
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
messy.cpp: In function 'void solve(int, int, std::vector<int>&)':
messy.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i = 0; i < lower.size(); i++) {
| ~~^~~~~~~~~~~~~~
messy.cpp:82:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for (int i = 0; i < lower.size(); i++) {
| ~~^~~~~~~~~~~~~~
messy.cpp:86:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i = 0; i < upper.size(); i++) {
| ~~^~~~~~~~~~~~~~
messy.cpp:90:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int i = 0; i < upper.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... |