75992024-01-10 00:49:00TuruTamasAutókódoláscpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms1896 KiB
2Elfogadva0/03ms2128 KiB
3Elfogadva2/23ms2332 KiB
4Elfogadva2/23ms2548 KiB
5Elfogadva2/23ms2780 KiB
6Elfogadva2/23ms2968 KiB
7Elfogadva2/23ms3184 KiB
8Elfogadva4/43ms3224 KiB
9Elfogadva4/43ms3228 KiB
10Elfogadva4/43ms3232 KiB
11Elfogadva4/43ms3228 KiB
12Elfogadva4/43ms3224 KiB
13Elfogadva4/43ms3612 KiB
14Elfogadva4/43ms3596 KiB
15Elfogadva4/43ms3564 KiB
16Elfogadva4/43ms3648 KiB
17Elfogadva4/43ms3656 KiB