This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma once
#include <vector>
#include <string>
#include <set>
using namespace std;
void add_element(std::string x);
bool check_element(std::string x);
void compile_set();
std::vector<int> restore_permutation(int n, int w, int r)
{
string s(n,'0');
set<string> aft,bef;
vector<int> p;
for(int i=0;i<n;i++)
p.push_back(i);
for(int i=0;i<(n-1);i++)
{
s[i]='1';
add_element(s);
bef.insert(s);
}
compile_set();
for(int mask=0;mask<(1<<n);mask++)
{
string t="";
for(int j=0;j<n;j++)
{
if(mask&(1<<j))
t+='1';
else
t+='0';
}
if(check_element(t))
{
aft.insert(t);
}
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
bool pos=1;
for(auto sp:bef)
{
swap(sp[i],sp[j]);
if(aft.find(sp)==aft.end())
{
swap(sp[i],sp[j]);
pos=0;
break;
}
swap(sp[i],sp[j]);
}
if(pos)
{
swap(p[i],p[j]);
return p;
}
}
}
return {};
}
Compilation message (stderr)
messy.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |