15262022-11-22 09:49:54TomaSajtAutókódoláscpp14Wrong answer 0/503ms3820 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;
    cout << ne(n) << ' ';
    ull pr = ~ne(~n);
    if ((pr >> 63) & 1) cout << "-1";
    else cout << pr;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1764 KiB
2Wrong answer0/02ms1924 KiB
3Wrong answer0/22ms2164 KiB
4Wrong answer0/22ms2332 KiB
5Wrong answer0/22ms2544 KiB
6Wrong answer0/22ms2648 KiB
7Wrong answer0/22ms2856 KiB
8Wrong answer0/42ms3020 KiB
9Wrong answer0/42ms3000 KiB
10Wrong answer0/42ms3152 KiB
11Wrong answer0/42ms3072 KiB
12Wrong answer0/42ms3200 KiB
13Wrong answer0/42ms3280 KiB
14Wrong answer0/42ms3280 KiB
15Wrong answer0/42ms3408 KiB
16Wrong answer0/42ms3612 KiB
17Wrong answer0/42ms3820 KiB