Submission #389332

#TimeUsernameProblemLanguageResultExecution timeMemory
389332Kevin_Zhang_TWBinary Subsequences (info1cup17_binary)C++17
0 / 100
1090 ms204 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; #define pb emplace_back #define AI(i) begin(i), end(i) template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); } template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); } #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() { cerr << endl; } template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); } template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; } #else #define DE(...) 0 #define debug(...) 0 #endif const int MAX_N = 2010, MAX_W = 30, inf = MAX_N - 5, p = 1e9 + 7; bool valid(int a, int b) { if (a == 0 && b == 0) return true; if (a < b) swap(a, b); a -= b + 1; if (a < 0) return false; return valid(a, b); } int cal(int a, int b, bool gen) { int res = 0, val = 0; while (a + b) { ++res; if (a < b) { b -= a + 1; val = val<<1; } else { a -= b + 1; val = val<<1|1; } } if (gen) { for (int i = 0;i < res;++i) cout << (val>>i&1) << " \n"[i+1==res]; } return res; } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); int T; cin >> T; while (T--) { int k; cin >> k; int cnt = 0; int need = inf, ind = -1; for (int i = 0;i <= k;++i) { if (valid(i, k - i)) ++cnt; if (chmin(need, cal(i, k - i, false))) ind = i; } cout << cnt << '\n'; cal(ind, k - ind, true); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...