Submission #983522

#TimeUsernameProblemLanguageResultExecution timeMemory
983522Faisal_SaqibPermutation (APIO22_perm)C++17
10 / 100
1072 ms464 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define vll vector<int> vector<int> cp(ll k)// O(lg n) { vector<int> ans; ll n_req=0; ll hb=-1; for(int j=59;j>=0;j--) { ll pw=(1ll<<j); if(k&pw) { if(hb==-1) { n_req+=j; hb=j; } else n_req++; } } ll last=n_req-1; int first=0; // cout<<last<<endl; for(int l=0;l<60 and l<hb;l++) { if(k&(1ll<<l)) { ans.push_back(first); first++; } if(first<=last) { ans.push_back(last); last--; } } reverse(begin(ans),end(ans)); return ans; } ll task(ll n) // O(lg n) { ll cp=0; for(int bit=59;bit>=0;bit--) { if(n&(1ll<<bit)) { cp+=bit; n^=(1ll<<bit); break; } } while(n) { cp++; n-=(n&-n); } return cp; } const ll SQ=21; int cpp(ll k) { ll mx=task(k); ll a=-1; ll b=k; for(ll d=2;d<=SQ and d<k;d++) { if(k%d==0) { ll f=cpp(d); ll s=cpp(k/d); if((f+s)<mx) { mx=f+s; a=d; b=k/d; } } } return mx; } vector<int> construct_permutation(ll k) { ll mx=task(k); ll a=-1; ll b=k; for(ll d=2;d<=SQ and d<k;d++) { if(k%d==0) { ll f=cpp(d); ll s=cpp(k/d); if((f+s)<mx) { mx=f+s; a=d; b=k/d; } } } if(a==-1) { return cp(k); } else{ vll ap=construct_permutation(a); vll bp=construct_permutation(b); ll nm=ap.size(); for(auto i:bp) ap.pb(i+nm); return ap; } return {}; }

Compilation message (stderr)

perm.cpp: In function 'int cpp(long long int)':
perm.cpp:67:8: warning: variable 'a' set but not used [-Wunused-but-set-variable]
   67 |     ll a=-1;
      |        ^
perm.cpp:68:8: warning: variable 'b' set but not used [-Wunused-but-set-variable]
   68 |     ll b=k;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...