By ayush29azad, history, 14 months ago, Can someone tell how for S>=2N, Petya wins in the following problem with also the approach?

By ayush29azad, history, 15 months ago, How is the below solution working ?? I found this in submission relatively easier than others . Can someone explain the intuition behind it? What I have understood is that we can move opposite to the direction s[i] in the string to get the required cooordinate. Can someone give a proper explanation for this and why are traversing string in the reverse direction?

#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
string s;
cin>>s;
int x=1,y=1;
for(int i=s.size()-1;i>=0;i--){
if(s[i]=='L'&&x<m)x++;
if(s[i]=='R'&&x>1)x--;
if(s[i]=='U'&&y<n)y++;
if(s[i]=='D'&&y>1)y--;

}
cout<<y<<" "<<x<<endl;
}
}

By ayush29azad, history, 16 months ago, Can someone help me in fiding error in my code ?? It is failing on a test case but I am not able to figure it out . Problem Link : https://codeforces.com/contest/1562/problem/C

My logic :

Case 1 — string contains all 1s then simply print starting and ending indexes of any two substrings of length greater than n/2. as they will be multiple of each other . like 11111111 >>> 1111 and 1111 their decimal values both will be multiple of each other .

Case 2 — if the first zero is finding at length less than or = to n/2 then print the index of a substring starting from there till the end and other excluding that zero and till the end. Like 101111 >>> 01111 and 1111, their decimal values both will be multiple of each other .

Case 3 — if the first zero is at length greater than n/2 then print the index of a substring starting from index 1 till it and the other starting from 1 to l-1. ****

I think it is failing on Case 1 But not able to figure it out why and where Please Help!!!!!

void solve()
{
ll n;cin>>n;string s;cin>>s;
ll l=-1;
for(int i=0;i<n;i++)
{
if(s[i]=='0')
{
l = i+1;
break;
}
}
if(l==-1)
{
cout<<1<<" "<<n/2<<" "<<n/2+1<<" "<<n<<"\n";return ;

}
if(l<=n/2)
{
cout<<l<<" "<<n<<" "<<l+1<<" "<<n<<"\n"; return ;
}
else
{
cout<<1<<" "<<l<<" "<<1<<" "<<l-1<<"\n";return ;

}

}

By ayush29azad, history, 16 months ago, Can someone help me in solving this game theory problem? I am not able to get the discussions /editorial , this problem is very tough . Please Help !!!!!!!!!!

https://leetcode.com/problems/stone-game-ix/

By ayush29azad, history, 16 months ago, The problem seems easy but there are two cases . I am not able to get case 2 which is explained in the editorial .

Case 1: First take out max of mixed flowers whcih we can make and then make individual flowers. long long mixed = min(min(r,g),b); r = r- mixed; g = g-mixed; b= b- mixed; long long ans1 = (mixed) +(r/3)+(g/3)+(b/3);

but I am not able to get case 2. maximum of two cases will be my answer.

By ayush29azad, history, 16 months ago, How to solve this problem using Dp ??? I read the editorial and found that it has been solved using combinatorics but I saw others have solved it using Dp approach.

By ayush29azad, history, 16 months ago, https://codeforces.com/problemset/problem/1313/C1

Can someone help me in solving this greedy problem ????

I thought of 2 passes left and right and storing max and then changing the elements and then comparing the sum of both sides(left and right) but it is not working , Can someone suggest a good approach to solve this problem. There is no tutorial for this problem .

By ayush29azad, history, 16 months ago, Yesterday 's contest had some very good problems , unfortunately, it became unrated.

The problem is based on standard topological sort Prerequisite problem .

If the cycle was found in the graph I printed -1 as the answer.

else I found the topical sort of all the chapters , using cycle detection + DFS + queue.

After finding the topological ordering of chapters (stored in a queue a ->b->c->d.... )how do I count the number of times I will have to read the book/number of passes required ???

By ayush29azad, history, 17 months ago, Can someone help me in solving this problem?? The problem editorial is tough to understand. It can be solved using hashmap +prefix sum but I am not able to the get the pattern/observation.

C. Good Subarrays Educational Codeforces Round 93 Problem Link :https://codeforces.com/problemset/problem/1398/C

By ayush29azad, history, 17 months ago, Can someone help me in solving this greedy problem ?? https://codeforces.com/problemset/problem/276/C I am not able to understand the editorial .

Thanks in advance !!!! Happy coding !!!

By ayush29azad, history, 18 months ago, How to solve this problem using bitmask or bit manuplation ??