judgeme's blog

By judgeme, history, 6 weeks ago, In English,

pls see the code in given image: - i think the problem is in sort(a,a+n,greater()) function because if i use sort(a,a+n) only this got accepted

 
 
 
 
  • Vote: I like it
  • -3
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by judgeme (previous revision, new revision, compare).

»
6 weeks ago, # |
  Vote: I like it -8 Vote: I do not like it

int main() { ll n;cin>>n; ll a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n,greater()); vector v; for(ll i=0;i<n;i++) { int flag = 0; v.PB(a[i]); for(ll j=0;j<n;j++) {

ll check = v.back();
       if( check%3==0 && binary_search(a,a+n,check/3)==true) v.PB(check/3);
       else if(binary_search(a,a+n,check*2)) v.PB(check*2);
       else {v.clear(); break;}
       if(v.size()==n){flag =1; break;}
   }
   if(flag==1) break;

} for(auto x:v) { cout<<x<<" "; } return 0; }

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it -8 Vote: I do not like it

    The current answer is

    int main() { ll n;cin>>n; ll a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n,greater()); vector v; for(ll i=0;i<n;i++) { int flag = 0; v.PB(a[i]); for(ll j=0;j<n;j++) {

    ll check = v.back(); if( check%3==0 && binary_search(a,a+n,check/3)==true) v.PB(check/3); else if(binary_search(a,a+n,check*2)) v.PB(check*2); else {v.clear(); break;} if(v.size()==n){flag =1; break;} } if(flag==1) break; } for(auto x:v) { cout<<x<<" "; } return 0; }