Submission #916331

#TimeUsernameProblemLanguageResultExecution timeMemory
916331rainboyBinary Subsequences (info1cup17_binary)C11
100 / 100
643 ms396 KiB
#include <stdio.h> #define INF 0x3f3f3f3f int length(int a, int b) { int l; if (b == 0) return a == 1 ? -1 : INF; l = length(b, a % b); return l == INF ? INF : l + a / b; } void print(int a, int b) { if (a < b) print(a, b - a), printf("0 "); else if (a > b) print(a - b, b), printf("1 "); } int main() { int t; scanf("%d", &t); while (t--) { int n, a, a_, k, l, l_; scanf("%d", &n), n += 2; k = 0, l_ = n, a_ = 0; for (a = 1; a < n; a++) { l = length(a, n - a); if (l != INF) { k++; if (l_ > l) l_ = l, a_ = a; } } printf("%d\n", k); print(a_, n - a_), printf("\n"); } return 0; }

Compilation message (stderr)

binary.c: In function 'main':
binary.c:24:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d", &t);
      |  ^~~~~~~~~~~~~~~
binary.c:28:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   scanf("%d", &n), n += 2;
      |   ^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...