Advertisement
Es7evam

Untitled

May 6th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define mk make_pair
  5. #define fi first
  6. #define se second
  7. #define fastcin ios_base::sync_with_stdio(false)
  8.  
  9. typedef long long ll;
  10. const int INF = 0x3f3f3f3f;
  11. const double PI = acos(-1.0);
  12. //int dp[]
  13.  
  14. int n;
  15. map<ll, int> mp;
  16. bool printed = false;
  17.  
  18. int go(ll cur, vector<ll> answ){
  19.     //cerr << "\ttam = " << answ.size() << endl;
  20.     if(answ.size() == n){
  21.         cout << answ[0];
  22.         for(int i=1;i<n;i++){
  23.             cout << " " << answ[i];
  24.         }
  25.         printed = true;
  26.     }
  27.     if(printed)
  28.         return 1;
  29.     int maxansw = 0;
  30.     if(cur%3 == 0){
  31.         if(mp[cur/3] != 0){
  32.             mp[cur/3]--;
  33.             answ.pb(cur/3);
  34.             maxansw = max(maxansw, go(cur/3, answ));
  35.             mp[cur/3]++;
  36.             answ.pop_back();
  37.         }
  38.     }
  39.     if(mp[cur*2] != 0){
  40.         mp[cur*2]--;
  41.         answ.pb(cur*2);
  42.         maxansw = max(maxansw, go(cur*2, answ));
  43.         mp[cur*2]++;
  44.         answ.pop_back();
  45.     }
  46. }
  47.  
  48. int main (void) {
  49.     fastcin;
  50.     cin >> n;
  51.     ll v[107];
  52.     for(int i=0;i<n;i++){
  53.         cin >> v[i];
  54.         mp[v[i]]++;
  55.     }
  56.  
  57.     map<ll,int> tmpmp;
  58.     vector<ll> answ;
  59.     for(int i=0;i<n;i++){
  60.         ll cur = v[i];
  61.         //cerr << "cur = " << cur << endl;
  62.         int cnt = 0;
  63.         answ.clear();
  64.         answ.pb(cur);
  65.         if(!printed){
  66.             go(cur, answ);
  67.         }
  68.     }
  69.     if(!printed)
  70.         cout << -1;
  71.     cout << endl;
  72.  
  73.     //vector <ll> answ;
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement