15282022-11-22 09:51:12TomaSajtAutókódoláscpp14Wrong answer 50/503ms3788 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;
typedef unsigned long long ull;

ull ne(ull n) {
    ull p1 = n & -n;
    ull m = n + p1 - 1; // right of the first 1 is all 1s
    ull p0 = ~m & (m + 1); // position of first 0 after the first bunch of 1
    ull masked = n & (p0 - 1);
    int c = __builtin_popcount(masked) - 1;
    ull res = n - masked + p0 + (1ull << c) - 1;
    return res;
}

int main() {
    speed;
    ull n; cin >> n;
    ull pr = ~ne(~n);
    if ((pr >> 63) & 1) cout << "-1";
    else cout << pr;
    cout << '\n' << ne(n);
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1768 KiB
2Wrong answer0/02ms1924 KiB
3Accepted2/22ms2128 KiB
4Accepted2/22ms2336 KiB
5Accepted2/22ms2416 KiB
6Accepted2/22ms2540 KiB
7Accepted2/22ms2764 KiB
8Accepted4/42ms2928 KiB
9Accepted4/42ms3132 KiB
10Accepted4/42ms3508 KiB
11Accepted4/42ms3448 KiB
12Accepted4/42ms3420 KiB
13Accepted4/42ms3644 KiB
14Accepted4/42ms3648 KiB
15Accepted4/42ms3644 KiB
16Accepted4/42ms3648 KiB
17Accepted4/42ms3788 KiB