Submission #410690

#TimeUsernameProblemLanguageResultExecution timeMemory
410690nichkeBinary Subsequences (info1cup17_binary)C++14
100 / 100
756 ms324 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e9 + 7; int n; int f(int x, int y) { int res = 0; while (y != 0) { res += x / y; x = x % y; swap(x, y); } if (x != 1) return INF; return res; } void print(int x, int y) { string s = ""; while (x != y) { if (x > y) { s += '0'; x -= y + 1; } else { s += '1'; y -= x + 1; } } int len = s.length(); for (int i = len - 1; i >= 0; i--) { cout << s[i] << ' '; } cout << endl; } void solve() { int cnt = 0, mn = INF, ind; for (int i = 0; i <= n; i++) { int val = f(i + 1, n + 1 - i); if (val < INF) cnt++; if (val < mn) { mn = val; ind = i; } } cout << cnt << endl; print(ind, n - ind); } signed main() { int t; cin >> t; while (t--) { cin >> n; solve(); } return 0; }

Compilation message (stderr)

binary.cpp: In function 'void solve()':
binary.cpp:49:7: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |  print(ind, n - ind);
      |  ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...