213942026-01-13 06:16:14BaKamillaAutókódoláscpp11Partially correct 43/501ms348 KiB
// MekkMester.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>

long long vissza(std::vector <short> v) {
    long long N = 0;
    long long p = 1;
    for (int i = 0; i < v.size(); i++) {
        N = N  + p * v[i];
        p = p * 2;
    }
    return N;
}

int main()
{
    long long N;
    std::cin >> N;
    std::vector <short> binaris;
    while (N != 0) {
        binaris.push_back(N % 2);
        N /= 2;
    }
    int i = 1;
    std::vector <short> s = binaris; 
    while (i < binaris.size() && (binaris[i]!=1 || binaris[i-1] != 0) ) i++;
    if (i < binaris.size()) {
        binaris[i] = 0;
        binaris[i-1] = 1;
        std::cout << vissza(binaris);
    }
    else std::cout << -1;
    binaris = s;
    int egy = 0;
    int zero = 0;
    i = 1;
    while (i < binaris.size() && (binaris[i] != 0 || binaris[i - 1] != 1)){
        i++;
        if(binaris[i - 1] == 1) egy++;
        else zero++;
    }
   // std::cout <<"\n" <<  binaris.size() << " " << i << "\n";
   // for (auto p : binaris) std::cout << p;
    if (i == binaris.size()) { binaris.push_back(1); }
    else
        binaris[i] =1;
    zero++;
    while (zero >= 0) {
        i--;
        binaris[i] = 0;
        zero--;
    }
    while (egy > 1) {
        i--;
        binaris[i] = 1;
        egy--;
    }
    /*std::cout << "\n";
    for(auto p:binaris ) std::cout << p;*/
    std::cout <<"\n" << vissza(binaris);
    
    

}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Partially correct1/21ms316 KiB
4Accepted2/21ms316 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted4/41ms316 KiB
9Accepted4/41ms316 KiB
10Accepted4/41ms332 KiB
11Accepted4/41ms316 KiB
12Accepted4/41ms316 KiB
13Partially correct2/41ms316 KiB
14Accepted4/41ms316 KiB
15Accepted4/41ms316 KiB
16Accepted4/41ms316 KiB
17Accepted4/41ms348 KiB