this_ability's blog

By this_ability, history, 30 hours ago, In English

Hey everyone, can someone tell me why this answer is wrong, I have checked the editorial as well, according to me it is same as written in editorial. The problem is Mike and Chocolate thieves My code:

include <bits/stdc++.h>

using namespace std; int main(){ long long int m; cin>>m; long long int l=0,r=5e15; long long int ans =-1; while(l<=r){ long long int mid = l+(r-l)/2; // capacity long long int count=0; for(long long int k=2;k<=1e5;k++){ long long int a = mid/(k*k*k); count+=a; }

if(count==m){
        ans = mid;
        r = mid-1;
    }
    else if(count>m) r = mid-1;
    else{
        l = mid+1;
    }
}
cout<<ans<<endl;

return 0;

}

Full text and comments »

  • Vote: I like it
  • -28
  • Vote: I do not like it

By this_ability, history, 3 weeks ago, In English

[submission:296009471][problem:1420C1]Hey Codeforces army..

I am stuck in this problem 1420 C1 : Pokemon Army (Easy version)

Approach : for every index i , i either pick the element and afterwards based on the previous index i add it or subtract else i do not pick the element. Here is my solution:

include <bits/stdc++.h>

using namespace std;

long long int call(vector<vector> &dp,vector arr,long long int idx, long long int state,long long int n){ if(idx>n) return 0; if(dp[idx][state]!=-1) return dp[idx][state];

int a=0, b = call(dp,arr,idx+1,state,n);
if(state ==1){
    a = arr[idx];
}else{
    a= -arr[idx];
}
a += call(dp,arr,idx+1,!state,n);
return dp[idx][state] = max(a,b);

} int main(){ int t; cin>>t; for(int i=0;i<t;i++){ long long int n,q; cin>>n>>q; vector arr(n+1,0); for(int j=0;j<n;j++) cin>>arr[j]; vector<vector> dp(n+1,vector(2,-1)); long long int ans = call(dp,arr,0,1,n); cout<<ans<<endl;

}
return 0;

}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it