Contest 2 - Hints to Problems [OFFICIAL]

don’t use INT_MAX use 1000001 as max value I got WA for 4 cases only because I was using INT_MAX

1 Like

i tried to use 1000001 instead of INT_MAX …bt still not working

Why is my Answer Wrong in the Question Rectangle ?

Here’s my Code:
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define pb push_back
#define b 100000
#define l 500
void solve()
{
ll n,x,y; cin>>n;
vector vec;
ll ans=1;
rep(i,0,n)
{
cin>>x>>y;
vec.pb(x);
}sort(all(vec));
rep(i,0,n-1)
{
ans=max(ans,(vec[i+1]-vec[i])*l);
}cout<<max(ans,(b-vec[n-1])*l);
}

Please Check my Logic… I think it’s correct but I am getting Wrong Answer. Please Tell any Example Test Case Where my Logic fails ??

1 Like

I have a doubt in compilers and pressers:

Input : <><><<>
Output : 6 or 4

Input : <<<<>
Output : 0 or 2

Please help me out.
Thank you

1 Like

4 and 0 respectively

2

its multiplied not added.

You haven’t checked the case when the whole x-axis is taken as the base and the minimum of all y coordinates as its height.
Also, initialize ans to (vec[0]-0)*l (also the case which you missed).

Thanks for Help !!!

But total number of valid pairs are 6 and 2 respectively…
can you please explain your answer…

<<><><>><<><><><>>
in the problem compilers and parsers …
what would be the output of the above testcase …can anyone please tell ??

If you read the question clearly, you will understand that, they are asking

you should tell the length of the longest prefix of each of these expressions that is valid

Since the above expression <<>><> is valid till the last closing brace, so the length(valid prefix ) is 6. Moreover, the length is same for all the expressions like <<>><> >* .
here: * - repeated

If you are still having issues solving the problem. I can give you one hint(Using stack). i.e, The longest prefix length is the index obtained, when you pop the stack’s last element.
Because for a expression to be valid prefix, One should have a corresponding ‘>’, for the first encountered ‘<’. Which is the stacks last element(first entered element). So the idea is that when ever we are about the pop the stack’s last remaining element, that means till there the expression is valid.

For eg:
if this is the expression “<<>><><<>” with length = 9 , indexing from 1.
The stack will become empty at two instances, when index = 4, 6. So we will save the indexes when we are about to pop the last element. So we will save the index=4, first. Then we will override it with the index=6, which is the answer. At the end of iterating throughout the expression, the stack will be left with ‘<’ at index=7. Since there is no corresponding ‘>’. Which is ok for us, since we got the answer already : )

4 Likes

Code for #COMPILER
why am i getting WA? for this code without the use of stack i have implemented?
?
code::

#include
#include
#include<bits/stdc++.h>

using namespace std;

int main()
{

int y;
cin>>y;
while(y>0){
std::string x;
cin>>x;
int l=x.length();
int count=0;
for(int i=0; i<l;i++){

	if (x[i]=='<'){

		for(int j=i+1;j<l;){
			if (x[j]=='>'){
				x[i]=0;
				x[j]=0;
				count=count+2;
				j=l;

				
			}
			j++;
		}
	}

}
cout<<count;
cout<<"\n";

y--;
}



return 0;

}

Infix and postfix hint…??? please provide it…

check the condition for winning and break, a slight silly mistake

see in the question description its given as an eg that ><>< is not valid;
i.e. the question says every < should have a > to be valid, and if we get > before a < everything after it becomes invalid, but the brackets before it remains valid if a valid pair <> exists

1 Like

Could you please ADD INFIX POSTFIX hints also…

Could anyone help–
My sol

Please…
It is giving some sort of compiler error that I don’t understand.

1 Like

You have made the code really complex and difficult to read;
Here look at my solution , ask if any doubt.

https://www.codechef.com/viewsolution/34700047

You can go to geeks for geeks for detailed explanation,
Here is the algorithm for it:
Scan the infix expression from left to right.
2. If the scanned character is an operand, output it.
3. Else,
…… 3.1 If the precedence of the scanned operator is greater than the precedence of the operator in the stack(or the stack is empty or the stack contains a ‘(‘ ), push it.
…… 3.2 Else, Pop all the operators from the stack which are greater than or equal to in precedence than that of the scanned operator. After doing that Push the scanned operator to the stack. (If you encounter parenthesis while popping then stop there and push the scanned operator in the stack.)
4. If the scanned character is an ‘(‘, push it to the stack.
5. If the scanned character is an ‘)’, pop the stack and and output it until a ‘(‘ is encountered, and discard both the parenthesis.
6. Repeat steps 2-6 until infix expression is scanned.
7. Print the output
8. Pop and output from the stack until it is not empty.