I also did with somewhat the same logic with a different.I think the minimum number of intersection is no_f 1’s in A+no_f 1’s in B-total string length and maximum is min(nof1’s in a,nof1’s in b)…
this is my code https://www.codechef.com/viewsolution/28365491
i dont know whats wrong with it.
thanks in advance
I used your logic and coded but still I am getting partially correct answer.Here is my code: #include #include #include #include #include #include <unordered_set>
using namespace std;
const long long int M = 1000000007;
long long int count_setbits(string s)
{
return count(s.begin(),s.end(),‘1’);
}
long long int fact(long long int n);
long long int nCr(long long int n,long long int r)
{
return fact(n) / (fact® * fact(n - r));
}
// Returns factorial of n
long long int fact(long long int n)
{
long long int res = 1;
for (long long int i = 2; i <= n; i++)
res = res * i;
return res;
}
int main()
{
long long int t;
cin >> t;
while (t–)
{
long long int n,max_setbits,min_setbits,intersection_setbits,answer=0;
cin >> n;
string a, b;
cin >> a >> b;
there are 2 problems in your code i can see.
problem 1. you should not calculate fact again and again , it may result in tle.
solution 1. simply use and array f[100001] ,something like this , and precompute it , and from fact(int n) , simply return f[n];
problem 2. nCr is not calulated this way for large numbers.
solution 2. use inverse modulo concept to calculate this.
I don’t think so you need special permissions , but yes you should make sure that you upload videos only after the contest is over (I always keep this in mind while uploading videos) , but there are people who upload videos during contest , they should understand what they are doing is wrong and should stop doing this.
Hi guys, I am getting WA when I take modulo inverse with 1000000007, and when I take with 1000000005, it gets accepted? Any reason behind this? Am I missing any concept?
Here is my correct solution: Link1
incorrect solution: Link2
you can use n C r+2 = ( (n-r)*(n - r - 1) /( (r + 2) *(r+1) ) *n C r so once calculated for minimum you can calculate it like for two jumps in O(1) space and time.