17962022-12-03 18:30:04kdbAutókódoláscpp11Accepted 50/503ms4288 KiB
#include <iostream>
#include <bitset>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s = bitset<40>(n).to_string();
    for (int a = 0; a < s.size() / 2; a++) swap(s[a], s[s.size() - a - 1]);
    string k = s, m = s;
    int i = 0;
    while (s[i] == '1') i++;
    int j = i + 1;
    while (j < s.size() && s[j] == '0') j++;
    if (j < s.size())
    {
        k[j] = '0';
        for (size_t a = 0; a < j; a++)
        {
            if (a >= j - i - 1) k[a] = '1';
            else k[a] = '0';
        }
        for (int a = 0; a < k.size() / 2; a++) swap(k[a], k[k.size() - a - 1]);
        cout << bitset<40>(k).to_ullong() << endl;
    }
    else cout << -1 << endl;

    i = 0;
    while (s[i] == '0') i++;
    j = i + 1;
    while (j < s.size() && s[j] == '1') j++;
    if (j < s.size())
    {
        m[j] = '1';
        for (size_t a = 0; a < j; a++)
        {
            if (a < j - i - 1) m[a] = '1';
            else m[a] = '0';
        }
        for (int a = 0; a < m.size() / 2; a++) swap(m[a], m[m.size() - a - 1]);
        cout << bitset<40>(m).to_ullong() << endl;
    }
    else cout << -1 << endl;

    return 0;
}
/*
46
-45
-51


*/
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/02ms2024 KiB
3Accepted2/22ms2224 KiB
4Accepted2/22ms2432 KiB
5Accepted2/22ms2508 KiB
6Accepted2/22ms2904 KiB
7Accepted2/22ms2904 KiB
8Accepted4/42ms3104 KiB
9Accepted4/42ms3188 KiB
10Accepted4/42ms3312 KiB
11Accepted4/42ms3548 KiB
12Accepted4/42ms3720 KiB
13Accepted4/42ms3800 KiB
14Accepted4/42ms4016 KiB
15Accepted4/42ms4092 KiB
16Accepted4/42ms4164 KiB
17Accepted4/42ms4288 KiB