Submission #433588

#TimeUsernameProblemLanguageResultExecution timeMemory
433588hhhhauraBinary Subsequences (info1cup17_binary)C++14
100 / 100
795 ms348 KiB
#define wiwihorz #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma loop-opt(on) #define rep(i, a, b) for(int i = a; i <= b; i ++) #define rrep(i, a, b) for(int i = b; i >= a; i--) #define all(x) x.begin(), x.end() #define ceil(a, b) ((a + b - 1) / (b)) #define INF 1000000000000000000 #define MOD 1000000007 #define eps (1e-9) using namespace std; #define int long long int #define lld long double #define pii pair<int, int> #define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()) #ifdef wiwihorz #define print(a...) kout("[" + string(#a) + "] = ", a) void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;} void kout() { cerr << endl; } template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); } #else #define print(...) 0 #define vprint(...) 0 #endif namespace solver { stack<int> ans; int count(int a, int b) { if(a == 0 && b == 0) return 0; if(a == b) return -1; if(a > b) { int k = a / (b + 1), ans = count(a - (b + 1) * k, b); return (ans == -1 ? -1 : ans + k); } else { int k = b / (a + 1), ans = count(a, b - (a + 1) * k); return (ans == -1 ? -1 : ans + k); } } void trace(int a, int b) { if(a == 0 && b == 0) return; if(a > b) ans.push(0), trace(a - b - 1, b); else ans.push(1), trace(a, b - a - 1); } void solve(int k) { int id = -1, best = INF, cnt = 0; rep(i, 0, k) { int cur = count(i, k - i); cnt += bool(cur != -1); if(cur != -1 && best > cur) best = cur, id = i; } trace(id, k - id); cout << cnt << "\n"; while(ans.size()) { int cur = ans.top(); ans.pop(); cout << cur << " \n"[ans.empty()]; } } }; using namespace solver; signed main() { ios::sync_with_stdio(false), cin.tie(0); int t; cin >> t; while(t --) { int k; cin >> k; solve(k); } return 0; }

Compilation message (stderr)

binary.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
binary.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
binary.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...