Submission #1114186

#TimeUsernameProblemLanguageResultExecution timeMemory
1114186PieArmyPermutation (APIO22_perm)C++17
100 / 100
2 ms508 KiB
typedef long long ll; ll pie(ll army){return (1ll<<army);} #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n' #define mid ((left+right)>>1) const ll inf=2000000000000000005; const int sonsuz=2000000005; using namespace std; ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} vector<int> construct_permutation(ll k){ vector<int>four; while(k){ four.pb(k&3); k>>=2; } reverse(four.begin(),four.end()); vector<int>res; int cnt=0; for(int i=0;i<four[0]-1;i++){ res.pb(-1); cnt++; } for(int i=1;i<four.size();i++){ if(four[i]==0){ res.pb(1); res.pb(1); } else if(four[i]==1){ res.pb(1); res.pb(1); res.pb(-1); cnt++; } else if(four[i]==2){ res.pb(1); res.pb(-1); res.pb(1); cnt++; } else if(cnt>=2){ res.pb(1); res.pb(1); res.pb(0); } else{ res.pb(1); res.pb(-1); res.pb(1); res.pb(-1); cnt+=2; } } vector<int>ans(res.size(),-1); int las=int(res.size())-1; for(int i=int(res.size())-1;i>=0;i--){ if(res[i]==1){ ans[i]=las--; } } if(res.size()){ las=0; vector<int>zero,one; for(int i=res.size()-1;i>=0;i--){ if(res[i]==-1){ ans[i]=las++; for(int x:one){ ans[x]=las++; } one=zero; zero.clear(); } else if(res[i]==0){ zero.pb(i); } } } return ans; } /* int main(){ ll n;cin>>n; vector<int>ans=construct_permutation(n); cout<<ans.size()<<endl; for(int x:ans)cout<<x<<" "; }*/

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(ll)':
perm.cpp:27:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i=1;i<four.size();i++){
      |              ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...