75992024-01-10 00:49:00TuruTamasAutókódoláscpp17Accepted 50/503ms3656 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("minta/be1.txt");
#define input in_file
#define INTHENAMEOFGOD
#else
#define input cin
#define INTHENAMEOFGOD \
    ios::sync_with_stdio(0); \
    cin.tie(0); \
    cout.tie(0);
#endif
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<ll, ll> pii;

ll N;

int main() {
    INTHENAMEOFGOD
    input >> N;
    bitset bits = bitset<64>(N);
    bool big = false, small = false;
    ll r_b = -1, r_s = -1;
    for (int i = 0; i < 63; i++) {
        if (!small && !bits[i] && bits[i+1]) {
            small = true;
            bitset b = bits;
            b[i] = true;
            b[i+1] = false;
            int first_before = 0;
            for (int k = 0; k < i; k++) {
                if (b[k])
                    first_before = k;
            }
            
            bitset<64> mask((b >> i) << i);
            b = (b << 64-i) >> 64-i;
            b <<= i-first_before-1;
            b |= mask;            
            r_s = b.to_ullong();
        }
        if (!big && bits[i] && !bits[i+1]) {
            big = true;
            bitset b = bits;
            b[i] = false;
            b[i+1] = true;
            size_t first = b._Find_first();
            bitset mask = (b >> i) << i;
            b <<= 64-i;
            b >>= 64-i+first;
            b |= mask;
            r_b = b.to_ullong();
        }
    }
    cout << r_s << "\n" << r_b << endl;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1896 KiB
2Accepted0/03ms2128 KiB
3Accepted2/23ms2332 KiB
4Accepted2/23ms2548 KiB
5Accepted2/23ms2780 KiB
6Accepted2/23ms2968 KiB
7Accepted2/23ms3184 KiB
8Accepted4/43ms3224 KiB
9Accepted4/43ms3228 KiB
10Accepted4/43ms3232 KiB
11Accepted4/43ms3228 KiB
12Accepted4/43ms3224 KiB
13Accepted4/43ms3612 KiB
14Accepted4/43ms3596 KiB
15Accepted4/43ms3564 KiB
16Accepted4/43ms3648 KiB
17Accepted4/43ms3656 KiB