67472023-12-18 17:59:34szasztundeAutókódoláscpp17Partially correct 46/504ms5584 KiB
#include <iostream>

using namespace std;

int main()
{
    int a[100000]={0},b[100000]={0},m=0;
    long long n;
    cin>>n;
    int t=n;
    while(n>0)
    {
        m++; a[m]=n%2; b[m]=n%2;
        n=n/2;
    }
    ///1
    int i=1,jo=0;
    while(i<m && !jo)
        if(a[i]==0 && a[i+1]==1) jo=1;
        else i++;
    a[i]=1; a[i+1]=0;
    if (a[m]==0)
    {
        int e=1,u=m-1;
        while(e<u){
            while(a[e]==0) e++;
            while(a[u]==1) u--;
            if(e<u) swap(a[e],a[u]);
            e++; u--;
        }
    }
    long long x=0,h=1;
    for(int j=1; j<=m; j++)
    {
        x=x+a[j]*h;
        h=h*2;
    }
    cout<<x<<endl;
    ///2
    i=1,jo=0;
    while(i<m && !jo)
        if(b[i]==1 && b[i+1]==0) jo=1;
        else i++;
    if(i==m) {b[i]=0; b[++m]=1; } else {b[i]=0; b[i+1]=1;}
    int e=1,u=i-1;
    while(e<u){
        while(b[e]==1) e++;
        while(b[u]==0) u--;
        if(e<u) swap(b[e],b[u]);
        e++; u--;
    }
    x=0; h=1;
    for(int j=1; j<=m; j++)
    {
        x=x+b[j]*h;
        h=h*2;
    }
    cout<<x;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base46/50
1Accepted0/03ms3420 KiB
2Accepted0/03ms3656 KiB
3Partially correct1/23ms3704 KiB
4Accepted2/23ms3924 KiB
5Accepted2/23ms4136 KiB
6Partially correct1/23ms4376 KiB
7Accepted2/23ms4608 KiB
8Accepted4/43ms4580 KiB
9Accepted4/43ms4644 KiB
10Accepted4/43ms4652 KiB
11Accepted4/43ms4928 KiB
12Accepted4/44ms5052 KiB
13Partially correct2/43ms5144 KiB
14Accepted4/43ms5356 KiB
15Accepted4/43ms5440 KiB
16Accepted4/43ms5456 KiB
17Accepted4/43ms5584 KiB