Code working on custom input but showing runtime error


#1

int Solution::solve(int A) {
if(A==1)return 1;
if(A==2)return 3;
int c = 2;
int i=1;
while(c < A){
c += (int)pow(2,(i%2 ? (i/2)+1 : i/2));
i++;
}
i–;
c -= (int)pow(2,(i%2 ? (i/2)+1 : i/2));
c++;
vector v(i+2,0);
v[0] = 1;
v[v.size()-1] = 1;
int offset = A-c;
i=v.size();
int rc=i/2,lc = (i%2) ? rc : rc-1 ;
int r=rc,l = lc;
while(offset){
if(r == v.size()-1 || l==0){
v[rc] = 1;
v[lc] = 1;
lc–;
rc++;
r=rc;
l=lc;
}
v[l] = 1;
v[r] = 1;
offset–;
if(!offset) break;
v[l] = 0;
v[r] = 0;
l–;
r++;
}
int res = 0;
for(int j=0;j<v.size();j++){
res = res | v[j];
res = res << 1;
}
res = res >> 1;
return res;
}