This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "messy.h"
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 500000000LL
#define EPS 0.00000001
#define pi 3.14159
ll mod=1000000007LL;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
ll N,B;
string BIT(vector<ll> pos)
{
string ans = ""; REP(i,0,N) {ans+='0';}
REP(i,0,pos.size()) {ans[pos[i]]='1';}
return ans;
}
string REV(string s)
{
REP(i,0,N) {if(s[i]=='0') {s[i]='1';} else {s[i]='0';}}
return s;
}
vector<int> restore_permutation(int n, int w, int r)
{
N=(ll) n; B=(ll)log2(N);
REP(i,0,B) {add_element(REV(BIT({1<<i})));}
vector<ll> pos={};
REP(i,0,B) {pos.pb(1<<i); add_element(BIT(pos));}
REP(i,0,B)
{
REP(j,0,N)
{
if((j&(1<<i))!=0LL && j!=(1<<i)) {add_element(BIT({1<<i,j}));}
}
}
compile_set();
vector<ll> rep,rep_or;
REP(i,0,N)
{
if(check_element(REV(BIT({i})))) {rep.pb(i);}
}
vector<bool> visited; REP(i,0,B) {visited.pb(false);}
string s=BIT({});
REP(i,0,B-1)
{
REP(j,0,B)
{
if(visited[j]) {continue;}
s[rep[j]]='1';
if(check_element(s)) {rep_or.pb(rep[j]); visited[j]=true; break;}
s[rep[j]]='0';
}
}
REP(i,0,B) {if(!visited[i]) {rep_or.pb(rep[i]); break;}}
rep=rep_or;
vector<ll> p; REP(i,0,N) {p.pb(0);}
visited.clear(); REP(i,0,N) {visited.pb(false);} REP(i,0,B) {visited[rep[i]]=true;}
ll OC;
REP(i,0,B)
{
vector<ll> asked; vector<ll> ones;
REP(j,0,1LL<<i) {asked.pb(0); ones.pb(0);}
OC = N/(1LL<<i);
REP(j,0,B)
{
if(j!=i) {asked[p[rep[j]]]++;}
}
asked[p[rep[i]]]++; ones[p[rep[i]]]++; p[rep[i]]=1<<i;
REP(j,0,N)
{
if(visited[j]) {continue;}
if(asked[p[j]]==OC-1)
{
asked[p[j]]=OC;
if(ones[p[j]]<OC/2) {ones[p[j]]++; p[j]+=(1<<i);}
}
else
{
if(check_element(BIT({rep[i],j}))) {asked[p[j]]++; ones[p[j]]++; p[j]+=(1<<i);}
else {asked[p[j]]++;}
}
}
}
return p;
}
Compilation message (stderr)
messy.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization ("O3")
|
messy.cpp:7: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
7 | #pragma GCC optimization ("unroll-loops")
|
# | 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... |