Submission #98429

#TimeUsernameProblemLanguageResultExecution timeMemory
98429keko37Binary Subsequences (info1cup17_binary)C++14
82 / 100
1060 ms388 KiB
#include<bits/stdc++.h> using namespace std; const int INF = 1000000007; int t, n; int f (int x, int y) { int sol = 0; while (y != 0) { sol += x/y; x = x % y; swap(x, y); } if (x != 1) return INF; return sol; } void ispis (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.size(); for (int i=len-1; i>=0; i--) { cout << s[i] << " "; } cout << endl; } void calc () { 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; ispis(ind, n - ind); } int main () { cin >> t; for (int i=0; i<t; i++) { cin >> n; calc(); } return 0; }

Compilation message (stderr)

binary.cpp: In function 'int f(int, int)':
binary.cpp:16:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if (x != 1) return INF; return sol;
     ^~
binary.cpp:16:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     if (x != 1) return INF; return sol;
                             ^~~~~~
binary.cpp: In function 'void calc()':
binary.cpp:48:10: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
     ispis(ind, n - ind);
     ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...