# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98433 | 2019-02-23T15:31:59 Z | keko37 | Binary Subsequences (info1cup17_binary) | C++14 | 602 ms | 460 KB |
#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 << '\n'; } void calc () { int cnt = 0, mn = INF, ind; for (int i=0; i<=n/2; i++) { int val = f(i+1, n+1 - i); if (val < INF) cnt++; if (val < mn) { mn = val; ind = i; } } cout << cnt*2 << '\n'; ispis(ind, n - ind); } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> t; for (int i=0; i<t; i++) { cin >> n; calc(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 376 KB | Output is correct |
2 | Correct | 49 ms | 460 KB | Output is correct |
3 | Correct | 50 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 598 ms | 384 KB | Output is correct |
2 | Correct | 602 ms | 284 KB | Output is correct |
3 | Correct | 589 ms | 384 KB | Output is correct |