1604 2022. 11. 28 20:37:00 kicsiboglar Autókódolás cpp11 Futási hiba 0/50 3ms 3988 KiB

#include <iostream>
#define ll long long 

using namespace std;

ll n, i, db=0;

bool construct(ll a, bool ok)
{
    ll nrb=0;
    while (a > 0)
    {
        if (a % 2 == 1) nrb++;
        a = a / 2;
    }
    if (ok) db = nrb;
    else if (nrb == db) return true;
    else return false;
}

int main()
{
   // ios::sync_with_stdio(false);
    cin >> n;
    construct(n, true);
    //cout << db;
    if(db == 1)
    {
        cout << n / 2 << "\n" << n * 2;
        return 0;
    }
    i = n - 1;
    while (i>=1)
    {
        if (construct(i, false))
        {
            cout << i;
            break;
        }
        --i;
    }
    if (i == 0) cout << "-1";
    cout << "\n";

    i = n + 1;
    bool ok = false;
    while (!ok)
    {
        ok = construct(i, false);
        if (ok)
        {
            cout << i;
            return 0;
        }
        ++i;
    }
    cout << "-1";
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Részfeladat Összpont Teszt Verdikt Idő Memória
base 0/50
1 Futási hiba 0/0 3ms 1976 KiB
2 Futási hiba 0/0 2ms 2168 KiB
3 Futási hiba 0/2 2ms 2368 KiB
4 Futási hiba 0/2 3ms 2924 KiB
5 Futási hiba 0/2 2ms 2988 KiB
6 Futási hiba 0/2 2ms 3176 KiB
7 Futási hiba 0/2 2ms 3164 KiB
8 Futási hiba 0/4 2ms 3364 KiB
9 Futási hiba 0/4 2ms 3644 KiB
10 Futási hiba 0/4 2ms 3988 KiB
11 Futási hiba 0/4 2ms 3760 KiB
12 Futási hiba 0/4 2ms 3564 KiB
13 Futási hiba 0/4 2ms 3840 KiB
14 Futási hiba 0/4 2ms 3884 KiB
15 Futási hiba 0/4 2ms 3820 KiB
16 Futási hiba 0/4 2ms 3752 KiB
17 Futási hiba 0/4 2ms 3772 KiB