for(; j<n&&w[j]^mx; ++j);
from above line of code w[j]^mx
I know it is xor operation.But what does this mean ?? why is this code used in editorial solution ? can anyone explain this ??
for(; j<n&&w[j]^mx; ++j);
from above line of code w[j]^mx
I know it is xor operation.But what does this mean ?? why is this code used in editorial solution ? can anyone explain this ??
When is xor 0?
When both the elements are same. Basically iterate until w[j]==mx.
What if N is odd number ? It is not mentioned in question.
My friend c++ is best for CP , you must go for STL in c++
Yes, I will.
What if N is odd number ? It is not mentioned in question.
Author can u help me out with Your solution I still can’t get ur logic how this work
Nice solution man
this is my code pls tell any 1 t.c on which it will fail
it is giving w.a. on submission
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector
#define mii map<int,int>
#define pqb priority_queue
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x;cin>>x;while(x–)
int mod = 1000000007;
class Triplet {
public:
int x;
int y;
int gcd;
};
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
Triplet extendedEuclid(int a, int b) {
if (b == 0) {
Triplet ans;
ans.gcd = a;
ans.x = 1;
ans.y = 0;
return ans;
}
Triplet smallAns = extendedEuclid(b, a % b);
Triplet ans;
ans.gcd = smallAns.gcd;
ans.x = smallAns.y;
ans.y = smallAns.x - (a / b) * smallAns.y;
return ans;
}
int modulo(int a, int m) {
Triplet ans = extendedEuclid(a, m);
return ans.x;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
w(t) {
int n;
cin >> n;
int arr[2 * n];
int maxi = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
maxi = max(arr[i], maxi);
}
int s = 2 * n;
for (int i = n; i < s; i++) {
arr[i] = arr[i - n];
}
int i = n + 1 , j = n + n / 2 ;
int ma[s + 1] = {};
ma[0] = 0;
if (arr[0] == maxi)
ma[1] = 1;
for (int i = 1; i <= s; i++) {
if (arr[i] == maxi)
ma[i + 1] = 1;
ma[i + 1] += ma[i];
// cout << ma[i] << ' ';
}
// cout << endl;
int count = 0;
// bool found = false;
while (i > 0) {
// cout << i << ' ' << j << " ";
// cout << ma[j] - ma[i] << " \n";
if (ma[j] - ma[i] == 0 && ma[i] == ma[i - 1]) {
// found = true;
count++;
// break;
}
i--;
j--;
// count++;
}
// if (!found) {
// cout << "0\n";
// // cout << "here\n";
// continue;
// }
cout << count << "\n";
}
return 0;
}
u can see my code same logic as yours but a bit change
https://www.codechef.com/viewsolution/34724696
Can anyone tell me what I am doing wrong here??
I can’t understand why this solution is getting WA verdict??
Thanks in advance.
please check my solution i did something like this
I guess, since max sweetness is 1 therefore chef can not eat according to his requirements.
So the correct answer would be zero.
please provide video editorial for this question
python solution here
If there is only one chocolate with maximum sweetness then we can avoid that by keeping it in the second half in N/2 ways.
If there are multiple chocolates with maximum sweetness then the idea is to find the maximum gap between any two of them. If the gap is less than N/2 then we cannot find a way to avoid them, Otherwise we can keep lesser sweet chocolates in the first half in gap - N/2 ways
can you send your code to me?