Problem link : contest practice Difficulty : Simple Prerequisites : basic math Solution : The problem is one of the easiest in the set. The solution is as follows. When we have an oddlength string S, we can make one turn and set some flag the the answer is even. Otherwise, we should keep in mind than the answer is odd. The remaining part always has even length, and we can threat the tree as the octary one and numerate the nodes by consecutive natural numbers. When we have found the node number in this tree, we will only need to multiply it by two and possibly to subtract one. The tree is octary, so the consecutive symbols can be grouped in pairs and each pair will denote a single edge of the tree. Namely, in the order from left to right the order of pairs is "ll", "lr", "rl", "rr". So we just maintain the variable index and each time we traverse one edge of our tree, we multiply it by 4, and then add 2, 1, 0 or 1, depending on the type of the edge: 2 for "ll", 1 for "lr" and so on. At the end we just need to find the indexth even (or odd) number. The parity depends on the parity of the length of the string that denotes the path. Setter's solution: link Tester's solution: link
This question is marked "community wiki".
asked 15 Sep '14, 15:32

Or we could do something like the following  For each level, keep a counter whether the level number is odd or even. We have ans = root = 1 Now traverse through the string.
Finally,
answered 15 Sep '14, 17:36
This wasn't working. TLE error.
(15 Sep '14, 21:57)
This worked for me. Are you sure nothing else was wrong with your code?
(16 Sep '14, 22:40)
It will work. It worked for me too. And most probably 90% of people have tackled this problem this way. @chefkaushik94 : Optimize your code.
(16 Sep '14, 22:46)
I did the same. But it shows WA. Can someone please tell my mistake? http://www.codechef.com/viewsolution/4807475
(17 Sep '14, 17:17)
Please someone let me know what's wrong with my code http://www.codechef.com/viewsolution/4811858 I followed the same method, and it worked for provided test cases, but on submission, it keeps showing wrong answer.
(20 Sep '14, 13:40)
@rok0707 modulo 10^9+7.
(02 Oct '14, 14:03)
hi.. here is your corrected solution https://www.codechef.com/viewsolution/7887676 here I want to mention something which you may havn't taken care first one when you are taking mod some even level value may be convert into odd value because there are so many times mode happen that's why you should a separate variable for keeping track of level or you can use index also second one may be your root[i] is exact multiple or equal to mod than root[i]%mod=0 later (may be )2*root[i]1 become negative hope it help you.. happy coding
(22 Aug '15, 17:23)
showing 5 of 7
show all

answered 16 Sep '14, 13:33

Can anyone tell me for which input my code is not working include<iostream>include<stdio.h>include<string.h>char s[1000000]; unsigned long long int flag=1,ans,x,a; using namespace std; int main() { unsigned long long int t,i,p=1,n=0,k=0,z=0; unsigned long long int flag,ans=1000000007,x; cin>>t; for(i=0;i<t;i++) { flag=1; p=1,n=0,k=0,z=0;
flag = flag % ans; printf("%lld\n",flag); } } answered 17 Sep '14, 10:16

Can someone please tell me what is wrong with my code found here http://www.codechef.com/viewsolution/4728506 answered 19 Sep '14, 17:34

Can anyone please figure it out why the enormous input method is unable to fetch the string from buffer ? Please!! //Chef LeftRight
answered 21 Sep '14, 11:48

Please help, getting WA!What's wrong with this python code? http://www.codechef.com/viewsolution/4862976 Pls help. answered 21 Sep '14, 17:30

I dont understand the editorial explanation, can someone elaborate in simple terms ? answered 18 Dec '14, 09:46

hi.. here is your corrected solution your corrected solution (AC) here I want to mention some points which you may havn't taken care POINT 1
Solution 1
POINT 2
Solution 2
hope it help you.. happy coding answered 22 Aug '15, 17:29

Can anyone let me know whats wrong with my solution. I have done the same but getting WA. https://www.codechef.com/viewsolution/18744849 Thanks in advance answered 03 Jun '18, 03:39
