Submission #781803

# Submission time Handle Problem Language Result Execution time Memory
781803 2023-07-13T11:07:28 Z Trunkty Binary Subsequences (info1cup17_binary) C++14
100 / 100
740 ms 360 KB
#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

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 time Memory Grader output
1 Correct 81 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 212 KB Output is correct
2 Correct 62 ms 304 KB Output is correct
3 Correct 59 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 720 ms 296 KB Output is correct
2 Correct 740 ms 300 KB Output is correct
3 Correct 719 ms 300 KB Output is correct