35252023-02-28 17:16:51horvathabelAutókódoláscpp17Wrong answer 27/503ms3884 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<<endl;
	}
	talalt=false;
	int cnte=0; 
	int cnta=0; 
vector<int> mego2; 
	for (int i=cnt-1; i>=0;i--){
		ll x=kettes[i];
		if (x==0 && (!talalt)){
		
			while (kettes[i]==0 && i>=0){
				i--; 
				mego2.push_back(0);
			}		
			talalt=true;
			mego2[mego2.size()-1]=1;
			i++;
		}
		else{
			if (talalt){
				if (x==1){
					cnte++;
				}
				cnta++;
			}
			else{
				mego2.push_back(x);
			}
		}
	} 
	for (int i=0; i<cnta+1-cnte;i++){
		mego2.push_back(0);
	}
	for (int i=0;i<cnte-1;i++){
		mego2.push_back(1);
	}
	ll z=1;
	ll ans=0; 
	for (int i=cnt-1; i>=0;i--){
		if (mego2[i]==1) ans+=z;
			z*=2; 
		}
	cout<<ans<<endl;
}
SubtaskSumTestVerdictTimeMemory
base27/50
1Accepted0/03ms1812 KiB
2Wrong answer0/03ms2012 KiB
3Wrong answer0/23ms2216 KiB
4Partially correct1/22ms2304 KiB
5Partially correct1/23ms2432 KiB
6Wrong answer0/23ms2644 KiB
7Partially correct1/23ms2860 KiB
8Partially correct2/43ms2972 KiB
9Partially correct2/43ms3064 KiB
10Partially correct2/42ms3052 KiB
11Accepted4/43ms3180 KiB
12Partially correct2/42ms3292 KiB
13Wrong answer0/42ms3296 KiB
14Partially correct2/43ms3396 KiB
15Accepted4/43ms3596 KiB
16Partially correct2/43ms3804 KiB
17Accepted4/43ms3884 KiB