#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> brut(int n)
{
for(int i=1;i<=n;i++)
{
string s="";
for(int j=0;j<i;j++)
s.push_back('1');
for(int j=0;j<n-i;j++)
s.push_back('0');
add_element(s);
}
compile_set();
string cur="";
for(int i=0;i<n;i++)
cur.push_back('0');
vector<int> perm(n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(cur[j]=='0')
{
cur[j]='1';
if(check_element(cur))
{
perm[j]=i;
break;
}
cur[j]='0';
}
}
}
return perm;
}
std::vector<int> restore_permutation(int n, int w, int r)
{
if(n==8) return brut(n);
int cntb=0;
while((1<<cntb)<n)
cntb++;
for(int i=0;i<cntb;i++)
{
string s="";
for(int j=0;j<=i;j++)
s.push_back('1');
for(int j=0;j<n-i-1;j++)
s.push_back('0');
add_element(s);w--;if(w<0)while(1);
s="";
for(int j=0;j<n;j++)
{
if(j==i) s.push_back('0');
else s.push_back('1');
}
add_element(s);w--;if(w<0)while(1);
}
for(int i=cntb;i<n;i++)
{
string pref="";
int cate=0;
for(int j=0;j<cntb;j++)
{
if((1<<j)&(i-cntb)) pref.push_back('1'), cate++;
else pref.push_back('0');
}
string suff="";
for(int j=cntb;j<n;j++)
{
if(j==i) suff.push_back('0');
else suff.push_back('1');
}
add_element(pref+suff);w--;if(w<0)while(1);
for(int j=cntb-1;j>=0;j--)
{
if(pref[j]=='1')
{
cate--;
pref[j]='0';
if(cate>0)
{
add_element(pref+suff);w--;if(w<0)while(1);
}
}
}
}
compile_set();
vector<int> poz_mici,poz_mari;
for(int i=0;i<n;i++)
{
string s="";
for(int j=0;j<n;j++)
{
if(i==j) s.push_back('0');
else s.push_back('1');
}
if(check_element(s))
poz_mici.push_back(i);
else
poz_mari.push_back(i);
}
assert((int)poz_mici.size() == cntb);
string cur="";
for(int i=0;i<n;i++)
cur.push_back('0');
vector<int> mici(cntb),sol(n);
for(int i=0;i<cntb;i++)
{
for(int j:poz_mici)
{
if(cur[j]=='0')
{
cur[j]='1';
if(check_element(cur))
{
mici[i]=j;
sol[j]=i;
break;
}
cur[j]='0';
}
}
}
for(int i=cntb;i<n;i++)
{
string s="";
for(int j=0;j<n;j++)
s.push_back('1');
for(int j=0;j<cntb;j++)
s[mici[j]]='0';
s[poz_mari[i-cntb]]='0';
//assert(check_element(s));
int sum=0;
for(int j=0;j<cntb;j++)
{
s[mici[j]]='1';
if(check_element(s))
{
sum += (1<<j);
}
else
s[mici[j]]='0';
}
//cerr<<i<<" "<<sum<<" zzz\n";
sol[poz_mari[i-cntb]]=sum+cntb;
}
return sol;
}
/*
16 1000 1000
7 6 12 5 14 15 10 0 3 11 9 4 13 1 2 8
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
*/
컴파일 시 표준 에러 (stderr) 메시지
messy.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
messy_c.h: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... |