Yessir, all correct answers on both the platforms. Solved every test case. (extremely sorry for late reply!)
Actually, according to what I know, a^b^c {(a raised to b) raised to c} should be abc^^.
The query made by that user is this: 
And as suggested by the other user, if we change the comparison operator we’ll get the correct expected outcome. But that actually made the answer for the other test cases wrong (for obvious reasons).
Also, I have one more apology to make as I did not format the test cases properly, it’s fixed now.
Here is the other query (more like a statement):

i am still confuse how to solve this can anyone help me to give more clarity on it. ?
ya !
if we change the comparison operator we’ll get the correct expected outcome. But that actually made the answer for the other test cases wrong (for obvious reasons).
My 1st submission was in this regard only and i got WA in that
my 1st submission
But just to satisfy all test case i tweeked the comparison operator in line(37) of my code
so my 2nd submission gave AC
my 2nd submission
2 Likes
I too feel now
the question is incomplete in regard to real algo’s understanding
But they made it less difficult by mentioning some constraints (supporting L-R logic)
R-L are rare on codechef i guess
I did not encountered it till date.
1 Like
Thanks bro!
You made me visualize it in easy manner !
tweek this line little bit to
while(!s.empty() && arr[s.top()] >= arr[i])
A very obvious observation for CHFQUEUE, I don’t know if it counts as a hint (probably not), so I hid it anyway.
Hint?
The array index starts from 1, 2, 3… (for values A1, A2, A3…)
Meaning, in the formula of the fearfulness we need to take index values that are indexed from 1.
Well, not really. Think of it like this:
For an array indexed from 1, the supposed value of every index will be usual_index_value + 1
.
So, let’s say, two usual index values are i and j. Hence, their supposed values will be I = (i + 1)
and J = (j + 1)
.
Now from the formula:
f = I - J + 1
(the values of I and J have meaning in accordance with the question)
But, I = i + 1
and J = j + 1
Therefore, f = i + 1 - j - 1 + 1
which is just f = i - j + 1
Hence, you don’t need to go through the trouble of wracking your brains for indexing stuff.
I hadn’t phrased the problem like that (it was the tester who changed it to be like that and I agreed with it because it is crystal clear. I can add this to the problem page here if necessary.
Wormholes ZCO12002
I tried to do it without using the std lib fn upper_bound(), lower_bound()
it gave TLE in some test cases of subtask 2
But it give 100% AC when i replaced my fn with these std lib fn ,
Though my fn performed same operation as the std lib,
But there are a lot of efforts done to make STL
so its fine to invoke STL whenever required than making our own function
as STL are well optimized but i don’t know how they optimized it before adding these feature to ANSI C++.
You are correct, I thought I was wrong, they should correct the test cases, so someone who solves the problem later does not have to search the forum or check where they are going wrong.
1 Like
Hi ,
Can anyone please help me to find out my mistake in below problem.
Problem: CodeChef: Practical coding for everyone
My Submission: CodeChef: Practical coding for everyone
Can someone help me figure out where I am going wrong in COMPILER?
#include "bits/stdc++.h"
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int tt;
cin >> tt;
for(int pp = 0 ; pp < tt ; pp++)
{
string s;
cin >> s;
ll n = s.length(),seq = 0;
ll i;
for (i = 0; i < n; i++)
if(s[i]=='<')
seq++;
else
if(seq == 0)
break;
else
seq--;
if(seq == 0)
cout << i;
else
cout << 0;
cout << endl;
}
return 0;
}
check this out.
int i=0,max=0,c=0;
while(s[i]!=’\0’)
{if(s[i]==’>’)
c–;
else
c++;
if(c<0)
break;
else if(c==0)
max=i+1;
i++;
}
cout<<max<<endl;
}
hope you will get your problm.
I dont understand why i am still getting the wrong answer for Compilers Question. Checking the hints, my solution satisfies all of them too. Can someone please help, by giving some direction to look into or some special testcase that i might be missing?
#include <iostream>
#include <bits/stdc++.h>
#define MAX 1000001
using namespace std;
int main() {
stack <int> s; //Stack for the brackets
long int t, i, j, maxPrefix; //maxPrefix will store length of valid prefix
char str[MAX], temp;
cin >> t;
while(t--) {
maxPrefix = 0; //Reset maxPrefix for each case
cin >> str;
for(i=0; str[i]!='\0' && i < MAX; i++) {
temp = str[i];
if(temp == '<') { //Push position if opening bracket
s.push(i);
}
else if(temp == '>') { //Pop if closing bracket
if(s.empty()) { //Closing brackets more than opening brackets
break; //So break from the str processing loop
}
else {
s.pop(); //Pop for closing bracket
if(s.empty()) { //Now, if stack empty means number of '<' == '>'
maxPrefix = i + 1; //Set to longest valid position, current position
}
}
}
}//End of one str scan loop
cout << maxPrefix << endl;
}//End of test cases loop
return 0;
}
1 Like
Guys I did solve it now. Im not sure if im allowed to post this comment as it fully solves the problem here.
If not, the mods might have to remove it, sorry.
Well, my stack was dirty from the previous cases basically.
solution to problem STFOOD is pretty straight forward, still i’m getting WA error…though same code is getting Accepted for every other submitters
problem link:- CodeChef: Practical coding for everyone
My Code :
` #include <stdio.h>
#include<limits.h>
int main()
{
int T;
scanf(“%d”,&T);
while(T--)
{
int i,N;
scanf("%d",&N);
long max_profit = -1;
for(i=0; i<N; i++)
{
int S,V,P;
scanf("%d %d %d",&S,&V,&P);
long profit = P/(S+1) * V;
if(profit > max_profit)
max_profit = profit;
}
printf("%ld\n",max_profit);
}
return 0;
}
`
why ?!!!
Wormholes: WA in Task-4
Could someone please point out which case my code is missing? I’m still a beginner. It would be a great help since I had spent a lot of time on this and I really need to know the error in this code.
n, x, y = map(int, input().split())
lst = []
for d in range(n):
lst.append(tuple(map(int, input().split())))
v = list(map(int, input().split()))
w = list(map(int, input().split()))
v.sort()
w.sort()
diff = 10000007
for q in range(n):
#find element in v
#binary search for first ele in v ##([q][0])
flag = 0
target = lst[q][0]
i = 0
j = len(v) - 1
mid = 0
#(target)
while(i < j):
mid = (i + j) // 2
if (target == v[mid]):
enter = v[mid]
#(enter)
flag = 1
break
elif target == v[mid + 1]:
enter = v[mid + 1]
flag = 1
break
elif (target < v[mid]):
if target >= v[mid - 1]:
enter = v[mid - 1]
#(enter)
flag = 1
break
j = mid-1
elif (target >= v[mid]):
if target < v[mid + 1]:
enter = v[mid]
#(enter)
flag = 1
break
i = mid + 1
if not flag:
if target >= v[0]:
enter = v[0]
#(enter)
else:
continue
#binary search for last ele in w ##([q][1])
flag = 0
target = lst[q][1]
i = 0
j = len(w) - 1
mid = 0
#(target)
while(i < j):
mid = (i + j) // 2
if (target == w[mid]):
exit = w[mid]
#(exit)
flag = 1
break
elif target == w[mid - 1]:
exit = w[mid - 1]
flag = 1
break
elif (target <= w[mid]) :
if (target > w[mid - 1]):
exit = w[mid]
flag = 1
#(exit)
break
j = mid - 1
elif (target > w[mid]):
if target <= w[mid + 1]:
exit = w[mid + 1]
flag = 1
#(exit)
break
i = mid + 1
if not flag:
if target <= w[0]:
exit = w[0]
#(exit)
else:
continue
#(enter, exit)
curr = exit-enter+1
diff = min(diff, curr)
print(diff)