35232023-02-28 16:57:55horvathabelAutókódoláscpp17Wrong answer 23/503ms3772 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long; 
int main() {
	ll n;
	cin>>n;
	vector<ll> kettes;
	ll cnt=0; 
	while (n>0){
		kettes.push_back(n%2);
		n/=2;
		cnt++; 
	}
	bool talalt=false;
	bool egyestalalt=false; 
	bool sorozat=true;
	vector<ll> mego;
	
	for (int i=0; i<cnt;i++){
		ll x=kettes[i];
		
		if (x==0 && (!talalt)){
		
			while (kettes[i]==0){
				i++; 
				mego.push_back(0);
			}		
			talalt=true;
			mego[mego.size()-1]=1;
			i--;
		}

		else{
			if (!egyestalalt && talalt){
				mego.push_back(0);
				egyestalalt=true;
			}

			else mego.push_back(x);
		}
	}
	reverse(mego.begin(),mego.end());
	if (!talalt or !egyestalalt){
		cout<<-1;
	}
	else{
		ll z=1;
		ll ans=0; 
		for (int i=cnt-1; i>=0;i--){
			if (mego[i]==1) ans+=z;
			z*=2; 
		}
	cout<<ans;
	}
	
}
SubtaskSumTestVerdictTimeMemory
base23/50
1Wrong answer0/03ms1808 KiB
2Wrong answer0/03ms2152 KiB
3Partially correct1/22ms2232 KiB
4Partially correct1/23ms2360 KiB
5Wrong answer0/23ms2360 KiB
6Wrong answer0/23ms2556 KiB
7Partially correct1/23ms2680 KiB
8Partially correct2/43ms2808 KiB
9Partially correct2/43ms3016 KiB
10Partially correct2/43ms3064 KiB
11Partially correct2/43ms3192 KiB
12Partially correct2/43ms3280 KiB
13Partially correct2/43ms3428 KiB
14Partially correct2/43ms3472 KiB
15Partially correct2/43ms3560 KiB
16Partially correct2/43ms3684 KiB
17Partially correct2/43ms3772 KiB