Submission #781803

#TimeUsernameProblemLanguageResultExecution timeMemory
781803TrunktyBinary Subsequences (info1cup17_binary)C++14
100 / 100
740 ms360 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll int t; int curr; vector<int> v; bool check(int a, int b, bool c){ if(a>b){ swap(a,b); } if(a==b){ if(a==0){ return true; } else{ return false; } } else{ int p = b/(a+1); if(c){ v.push_back(p); } curr += p; b -= p*(a+1); return check(b,a,c); } } signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> t; for(int i=1;i<=t;i++){ int n; cin >> n; int ans=0,mini=2e9,pos; for(int i=0;i<=n;i++){ curr = 0; if(check(i,n-i,false)){ ans++; if(curr<mini){ mini = curr; pos = i; } } } cout << ans << "\n"; v.clear(); check(pos,n-pos,true); reverse(v.begin(),v.end()); for(int i=0;i<v.size();i++){ for(int j=1;j<=v[i];j++){ cout << i%2 << " "; } } cout << "\n"; } return 0; }

Compilation message (stderr)

binary.cpp: In function 'int main()':
binary.cpp:55:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int i=0;i<v.size();i++){
      |                     ~^~~~~~~~~
binary.cpp:53:14: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |         check(pos,n-pos,true);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...