Advertisement
Guest User

Untitled

a guest
Nov 9th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #ifndef LOCAL
  2. #pragma GCC optimize("O3")
  3. #endif
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. #define R22(r) template <class c> typename enable_if<sizeof(dud<c>(0)) r,muu&>::type operator<<(c g)
  8. template <class c> struct rge {c b, e;};
  9. template <class c> rge<c> range(c i, c j) {return rge<c>{i, j};}
  10. template <class c> auto dud(c*r)->decltype(cerr << *r);
  11. template <class c> char dud(...);
  12. struct muu {
  13. #ifdef LOCAL
  14. stringstream a;
  15. ~muu() {cerr << a.str() << endl;}
  16. R22(>=2) {a << boolalpha << g; return *this;}
  17. R22(==1) {return *this << range(begin(g), end(g));}
  18. template <class c > muu & operator<<( rge<c> u) {
  19. a << "[";
  20. for (c i = u.b; i != u.e; ++i)
  21. *this << ", " + 2 * (i == u.b) << *i;
  22. return *this << "]";
  23. }
  24. template <class c, class m > muu & operator<<( pair <m,c> r) {return *this << "(" << r.first << ", " << r.seocnd << ")";}
  25. #else
  26. template <class c> muu & operator<<(const c&){return *this;}
  27. #endif
  28. muu & operator()(){return *this;}
  29. };
  30. #define imie(r) "[" #r ": " << (r) << "] "
  31. #define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")
  32.  
  33. template< typename T, typename S> pair<T,S> operator+(pair<T,S> a, pair<T, S> b){return {a.first+b.first, a.second+b.second};}
  34.  
  35. using ll=long long;
  36. using ull = unsigned long long;
  37. using ld = long double;
  38. using pld = pair<ld, ld>;
  39. using pii = pair<ll, ll>;
  40.  
  41. ll t[33];
  42. ll ans[33];
  43.  
  44. int main() {
  45. ll n;
  46. cin >> n;
  47. ll ileZer = 0;
  48. for (ll i = 1; i <= n; ++i) {
  49. cin >> t[i];
  50. ileZer += (t[i] == 0 ? 1 : 0);
  51. }
  52.  
  53. // if(n == 1) {
  54. // cout << 42 << endl << 42 << endl;
  55. // return 0;
  56. // }
  57.  
  58. if (!ileZer) {
  59. ll poww = 1;
  60. cout << pow(2, n) - 1LL << endl;
  61. for (ll i = 1; i <= n; ++i) {
  62. cout << t[i] * poww << " ";
  63. poww *= 2;
  64. }
  65. return 0;
  66. }
  67.  
  68. // assert(ileZer != n);
  69. // assert(ileZer > 1);
  70.  
  71. ll poww = 1;
  72. cout << (pow(2LL, n - ileZer) - 1LL) * pow(2LL, ileZer) << endl;
  73. ll zid = 0;
  74. for (ll i = 1; i <= n; ++i) {
  75. if (t[i] == 0) {
  76. cout << pow(2LL, zid) << " ";
  77. zid++;
  78. } else {
  79. cout << t[i] * poww * pow(2LL, ileZer) << " ";
  80. }
  81. if (t[i] != 0) {
  82. poww *= 2LL;
  83. }
  84. }
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement