Submission #917225

# Submission time Handle Problem Language Result Execution time Memory
917225 2024-01-27T13:23:51 Z andrei_iorgulescu Binary Subsequences (info1cup17_binary) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 25;
const int K = 100000;

int a;
int sol[K + 5];
int solLength[K + 5];
int dp0,dp1,sumdp;


void afis(int M)
{
    if (solLength[sumdp] == 0 or M < solLength[sumdp])
    {
        solLength[sumdp] = M;
        sol[sumdp] = a;
    }
}

void bkt(int pos,int pz,int sumant)
{
    if (sumdp > K)
        return;
    if (pos != 1)
        afis(pz - 1);
    if (pz == N + 1)
        return;
    else
    {
        if (pos & 1)
        {
            if (pos == 1)
            {
                dp0 = 1;
                dp1 = 1;
                for (int lung = 1; lung <= N; lung++)
                {
                    a &= ~(1 << (pz + lung - 1));
                    sumdp = lung;
                    bkt(pos + 1,lung + 1,lung);
                }
            }
            else
            {
                dp0 += sumant;
                for (int lung = 1; lung <= N - pz + 1; lung++)
                {
                    a &= ~(1 << (pz + lung - 1));
                    sumdp += dp0 * lung;
                    bkt(pos + 1,pz + lung,dp0 * lung);
                    sumdp -= dp0 * lung;
                }
                dp0 -= sumant;
            }
        }
        else
        {
            dp1 += sumant;
            for (int lung = 1; lung <= N - pz + 1; lung++)
            {
                a |= 1 << (pz + lung - 1);
                sumdp += dp1 * lung;
                bkt(pos + 1,pz + lung,dp1 * lung);
                sumdp -= dp1 * lung;
            }
            dp1 -= sumant;
        }
    }
}

int phi[1000005];
const int NMAX = 1e6 + 2;

void prec_phi()
{
    for (int i = 1; i <= NMAX; i++)
        phi[i] = i;
    for (int i = 2; i <= NMAX; i++)
        if (phi[i] == i)
            for (int j = i; j <= NMAX; j += i)
                phi[j] = (phi[j] / i) * (i - 1);
}


signed main()
{
    //for (int i = 1; i <= N; i++)
      //  found[i] = true;
    bkt(1,1,0);
    //for (int i = 1; i <= 50; i++)
      //  cout << sol[i].size() << endl;
    //bktsus(1,1,0);
    prec_phi();
    /*for (int i = 1; i <= K; i++)
        if (!found[i])
            cout << i << endl;*/
    //for (int i = 1; i <= N; i++)
      //  cout << i << ' ' << cnt[i] << ' ' << cnt2[i] << endl;
    int tc;
    cin >> tc;
    while (tc--)
    {
        int kk;
        cin >> kk;
        cout << phi[kk + 2] << '\n';
        for (auto it : sol[kk])
            cout << it << ' ';
        cout << '\n';
    }
    return 0;
}

Compilation message

binary.cpp: In function 'int main()':
binary.cpp:109:30: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
  109 |         for (auto it : sol[kk])
      |                              ^
      |                              std::begin
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from binary.cpp:1:
/usr/include/c++/10/valarray:1224:5: note: 'std::begin' declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
binary.cpp:109:30: error: 'end' was not declared in this scope; did you mean 'std::end'?
  109 |         for (auto it : sol[kk])
      |                              ^
      |                              std::end
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from binary.cpp:1:
/usr/include/c++/10/valarray:1244:5: note: 'std::end' declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~