When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

vohrab1896's blog

By vohrab1896, history, 2 years ago, In English

Hi everyone, I am currently preparing for Software Engineering interviews. If anyone else is also preparing for the same and wants to prepare together then please email me at [email protected]. It will be helpful to have a teammate while preparing otherwise its easy to loose motivation. Thanks

Full text and comments »

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

By vohrab1896, history, 3 years ago, In English

Hi CF community I have been a newbie from quite a long time and performing at a highly low rate. I want to do CP but loosing much motivation now but still want to keep this as a top priority and not give up because of which I can't switch to anything else thus ending in a very dead end loop. I know this answer is "practice". No other substitute. Upsolving questions till D still taking a lot of time to think. Sometimes I think too slow and because of that not able to complete question in small time. Because of that I have to look at the editorial. Nowadays, a single D question is taking my whole day. I am doing questions daily. I know I am not effective. It is a dead end loop. Can't figure out. Any help is appreciated. Thanks

Full text and comments »

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

By vohrab1896, history, 4 years ago, In English

Hi all

I am getting WA in SPOJ-TOPOSORT. I solved it using Kahn's Algorithm but getting WA. To get smallest value on second place I am picking up smallest value from the child nodes of the node present at the front of queue and then comparing it's value to other value present in the front of queue. This is the link- [https://ideone.com/Yur2cr]. I have given a lot of time to find the wrong test case but failed. If anyone is able to solve this then please let me know.

Thanks

Full text and comments »

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

By vohrab1896, history, 4 years ago, In English

Hey CF Community! I have done this question ( https://codeforces.com/contest/1300/problem/C ) using prefix and suffix arrays but getting WA. As explained in the editorial firstly I calculated prefix and suffix value (~a[0])&(~a[1])... for each location. Then multiplied by a[i] for each i. But, I am getting WA. Following is my code. Please feel free to help. Thanks.

include<bits/stdc++.h>

using namespace std;

define forn(i,l,r) for(int i=l;i<r;i++)

define fore(i,n) forn(i,0,n)

int a[100001]; int prefix[100001],suffix[100001]; int main() { int n;

cin>>n;

fore(i,n)
 cin>>a[i];

int ipos=0;

forn(i,0,n)
{
    if(i==0)
     prefix[0]=1073741823;
    else prefix[i]=prefix[i-1]&(~(a[i-1]));
}

for(int i=n-1;i>=0;i--)
{
    if(i==n-1)
       suffix[i]=1073741823;
    else suffix[i]=(~a[i+1])&(suffix[i+1]);
}
int max_val=INT_MIN;
for(int i=0;i<=n-1;i++)                                                                 
{
    if(a[i]&(prefix[i]&suffix[i])>max_val)
    {
       max_val=a[i]&(prefix[i]&suffix[i]);
       ipos=i;
    }
}
cout<<a[ipos];

fore(i,n)
    if( ipos!=i)
       cout<<" "<<a[i];

return 0;

}

Full text and comments »

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

By vohrab1896, history, 5 years ago, In English

Hi CF community! I have been solving this problem(https://www.codechef.com/JUNE19B/problems/CHFING) from quite a few days. Previously, I didn't know about Frobenius Numbers and then I solved this using it but still getting Wrong Answer. Here is my code

#include<bits/stdc++.h>


using namespace std;

long long fast_pow(long long base, long long n,long long M)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fast_pow(base,n/2,M);
    if(n%2==0)
        return ( halfn * halfn ) % M;
    else
        return ( ( ( halfn * halfn ) % M ) * base ) % M;
}
long long findMMI_fermat(long long n,long long M)
{
    return fast_pow(n,M-2,M);
}
int main()
{
	int t;
	long long n,k;
	cin>>t;
	while(t--)
	{
		long long a=1000000007;
		cin>>n>>k;
		
		if(k==1)cout<<"0"<<endl;
		else
		{
			long long l=findMMI_fermat(n-1,a);
		 long long f=(((((((k-2)%a)*l)%a)*(k%a))%a+k)%a-1)%a;
		if(f<(k))cout<<(k-1)%a<<endl;
		else
		{
		long long count=0;

		long long l1=findMMI_fermat(k,a);
		long long f1=((f+1)%a*(l1%a))%a;
		long long f2;
		
		f2=(((((f1-1)%a)*(f1)%a)%a)/2)%a;
	
		count=((((f2%a)*((n-1)%a))%a+f1)%a-1)%a;
	
		cout<<(f%a-(count)%a+a)%a<<endl;
	    }
	    }
	}
	
	
	return 0;
}

Also, I have a doubt in using Fermat's Theorem. In (a/b)%m, if a is not divisible by b, it is giving a large number than expected. Maybe I am somewhere wrong in my concept. Please help if possible. Thanks.

Full text and comments »

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