Submission #782030

#TimeUsernameProblemLanguageResultExecution timeMemory
782030AndreyBinary Subsequences (info1cup17_binary)C++14
100 / 100
590 ms364 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int k,ans = 0,a = 0,b = 0,br = 0,sm = INT_MAX,c; cin >> k; for(int i = 0; i <= k; i++) { a = i; b = k-i; br = 0; while(a != b) { if(a < b) { swap(a,b); } br+=a/(b+1); a%=b+1; } if(a == 0 && b == 0) { ans++; if(br < sm) { sm = br; c = i; } } } vector<int> wut(0); a = c; b = k-c; while(a != b) { if(a > b) { wut.push_back(0); a-=b+1; } else { wut.push_back(1); b-=a+1; } } cout << ans << "\n"; for(int i = 0; i < wut.size(); i++) { cout << wut[i] << " "; } cout << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) { solve(); } return 0; }

Compilation message (stderr)

binary.cpp: In function 'void solve()':
binary.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 0; i < wut.size(); i++) {
      |                    ~~^~~~~~~~~~~~
binary.cpp:28:10: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |     b = k-c;
      |         ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...