Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef LOCAL
- #pragma GCC optimize("O3")
- #endif
- #include <bits/stdc++.h>
- using namespace std;
- #define R22(r) template <class c> typename enable_if<sizeof(dud<c>(0)) r,muu&>::type operator<<(c g)
- template <class c> struct rge {c b, e;};
- template <class c> rge<c> range(c i, c j) {return rge<c>{i, j};}
- template <class c> auto dud(c*r)->decltype(cerr << *r);
- template <class c> char dud(...);
- struct muu {
- #ifdef LOCAL
- stringstream a;
- ~muu() {cerr << a.str() << endl;}
- R22(>=2) {a << boolalpha << g; return *this;}
- R22(==1) {return *this << range(begin(g), end(g));}
- template <class c > muu & operator<<( rge<c> u) {
- a << "[";
- for (c i = u.b; i != u.e; ++i)
- *this << ", " + 2 * (i == u.b) << *i;
- return *this << "]";
- }
- template <class c, class m > muu & operator<<( pair <m,c> r) {return *this << "(" << r.first << ", " << r.seocnd << ")";}
- #else
- template <class c> muu & operator<<(const c&){return *this;}
- #endif
- muu & operator()(){return *this;}
- };
- #define imie(r) "[" #r ": " << (r) << "] "
- #define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")
- 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};}
- using ll=long long;
- using ull = unsigned long long;
- using ld = long double;
- using pld = pair<ld, ld>;
- using pii = pair<ll, ll>;
- ll t[33];
- ll ans[33];
- int main() {
- ll n;
- cin >> n;
- ll ileZer = 0;
- for (ll i = 1; i <= n; ++i) {
- cin >> t[i];
- ileZer += (t[i] == 0 ? 1 : 0);
- }
- // if(n == 1) {
- // cout << 42 << endl << 42 << endl;
- // return 0;
- // }
- if (!ileZer) {
- ll poww = 1;
- cout << pow(2, n) - 1LL << endl;
- for (ll i = 1; i <= n; ++i) {
- cout << t[i] * poww << " ";
- poww *= 2;
- }
- return 0;
- }
- // assert(ileZer != n);
- // assert(ileZer > 1);
- ll poww = 1;
- cout << (pow(2LL, n - ileZer) - 1LL) * pow(2LL, ileZer) << endl;
- ll zid = 0;
- for (ll i = 1; i <= n; ++i) {
- if (t[i] == 0) {
- cout << pow(2LL, zid) << " ";
- zid++;
- } else {
- cout << t[i] * poww * pow(2LL, ileZer) << " ";
- }
- if (t[i] != 0) {
- poww *= 2LL;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement