Submission #1114157

#TimeUsernameProblemLanguageResultExecution timeMemory
1114157PieArmyPermutation (APIO22_perm)C++17
0 / 100
1 ms336 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; } } int las=0; vector<int>ans(res.size()); for(int i=int(res.size())-1;i>=0;i--){ if(res[i]==-1){ ans[i]=las++; } } las=int(res.size())-1; for(int i=int(res.size())-1;i>=0;i--){ if(res[i]==1){ ans[i]=las--; } } int mn=sonsuz; for(int i=0;i<res.size();i++){ if(res[i]==0){ ans[i]=mn+2; } else mn=min(mn,ans[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++){
      |              ~^~~~~~~~~~~~
perm.cpp:71:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i=0;i<res.size();i++){
      |              ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...