123552024-12-13 08:36:56szasztundeAutókódoláscpp17Részben helyes 45/502ms1372 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base45/50
1Elfogadva0/02ms1080 KiB
2Elfogadva0/02ms1080 KiB
3Részben helyes1/22ms1080 KiB
4Elfogadva2/22ms1080 KiB
5Részben helyes1/22ms1308 KiB
6Részben helyes1/22ms1152 KiB
7Elfogadva2/22ms1204 KiB
8Elfogadva4/42ms1084 KiB
9Elfogadva4/42ms1080 KiB
10Elfogadva4/42ms1080 KiB
11Elfogadva4/42ms1112 KiB
12Elfogadva4/42ms980 KiB
13Részben helyes2/42ms1372 KiB
14Elfogadva4/42ms1080 KiB
15Elfogadva4/42ms1080 KiB
16Elfogadva4/42ms1080 KiB
17Elfogadva4/41ms1080 KiB