Блог пользователя soumil_10

Автор soumil_10, история, 9 часов назад, По-английски

I am unable to understand why the my solution is wrong (failing on test case 2) for the this question: 2072C - Creating Keys for StORages Has Become My Main Skill Can someone please explain what am i missing here?

include <bits/stdc++.h>

using namespace std;

define dbg(v) \

cerr << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;

define int long long

void scanarr(int arr[], int n) { for(int i = 0; i < n; i++) cin >> arr[i]; }

int order(int x){
int ans = 0; while(x!=0){ if(x/2 != 0) ans++; x /= 2; } return ans; }

int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int t;
cin>>t;
while(t--){
    int n,x;
    cin>>n>>x;
    int p=0, x1=x;
    while(x1!=0){
        if(x1%2 == 0) break;
        p++;
        x1 /= 2;
    }//cout<<p<<'\n';
    int a[31];
    a[0] = 1;
    for(int i=1; i<31; i++){
        a[i] = a[i-1]*2;
    }
    int mex = a[p];
    if(mex >= n){
        for(int i=0; i<n-1; i++){
            cout<<i<<" ";
        }
        if(order(n-1) == order(x)) cout<<n-1<<'\n';
        else cout<<x<<'\n';
    }else{
        for(int i=0; i<n-1; i++){
            if(i>= mex){
                cout<<0<<" ";
            }else   
            {
                cout<<i<<" ";
            }
        }cout<<x<<'\n';
    }
}
return 0;

}

Полный текст и комментарии »

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится