35272023-02-28 17:23:57horvathabelAutókódoláscpp17Wrong answer 31/503ms4308 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long; 
int main() {
	ll n;
	cin>>n;
	int u=n;
	vector<ll> kettes;
	ll cnt=0; 
	int cntz=0; 
	while (n>0){
		kettes.push_back(n%2);
		if (n%2==1) cntz++; 
		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<<endl;
	}
	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; 
	if (cntz==1){
		cout<<u*2;
	}
	else{
	for (int i=cnt-1; i>=0;i--){
		if (mego2[i]==1) ans+=z;
			z*=2; 
		}
	cout<<ans<<endl;
}
}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/03ms1816 KiB
2Wrong answer0/03ms2048 KiB
3Partially correct1/23ms2300 KiB
4Accepted2/23ms2472 KiB
5Partially correct1/23ms2680 KiB
6Wrong answer0/23ms2904 KiB
7Partially correct1/23ms3124 KiB
8Partially correct2/43ms3356 KiB
9Partially correct2/43ms3504 KiB
10Partially correct2/43ms3744 KiB
11Accepted4/43ms3960 KiB
12Partially correct2/42ms4176 KiB
13Partially correct2/42ms4076 KiB
14Partially correct2/42ms4108 KiB
15Accepted4/42ms4096 KiB
16Partially correct2/43ms4088 KiB
17Accepted4/43ms4308 KiB