Coding Games and Programming Challenges to Code Better

**Some** of the testcases contain trailing spaces in **some** input lines.

I don’t know about the validators.

Coding Games and Programming Challenges to Code Better

**Some** of the testcases contain trailing spaces in **some** input lines.

I don’t know about the validators.

Thanks for reporting.

I removed the trailing spaces from the first 5 testcases and their validators, the rest was fine.

2 Likes

https://www.codingame.com/training/medium/the-grand-festival—i

Hi, I’ve some issues solving this fully. I pass all Tests except for the last one with 365 Tournament days. This test times out. If I run it on my machine it takes about 13.6s to complete. I’m doing memoization and some tricks here and there but I don’t know how to speed this up…

Can someone have a look at my code?

Edit: Deleted my code so I dont spoiler someone. But can send it via PM.

I’ve got help from @eulerscheZahl who showed me that I don’t had to track all the price money I’ve had in the nodes above a node that I’m currently investigating. I just had do pass upwards what I’ve got in the subtree und add it together. Now even the last test case only runs for 200ms or something like that on my machine. Thanks a lot

1 Like

HI,

I’ve got an issue with test and validator.

In the IDE, the test 7 is OK but the test 8 FAIL but when I send the code, the test 7 FAIL and the test 8 is OK

What is wrong my code or the validation process ?

Let me now if you want to see my code.

have a good day

There are no problems with the validation process, your algorithm is probably wrong.

Try to understand why your testcase 8 doesn’t give the expected answer, it might also help fixing validator 7.

ok, I will see …

Hi all,

i’m having trouble with the game named " Grand Festival 1"; actually i can’t figure it out (i think).

Can someone convalid this “algorithm”, at least in principle? Can it work or it is too big and not handlable? And more: HTF do i implement this sort of tree ?

My idea is:

node has 2 property: value and dayLeft (number of days u can contiune playng)

create a binary tree with these rules:

- the rootNode is 0 with dayLeft = R

- starting from root: add to current node a left child the same value of current node and dayLeft = R (couse u rested, and now the maximum sequence is available); and a right child with value = value of current node + PRIZE , and dayLeft = current node dayLeft -1 ;

So it mimics a structure where on the left child of a node i have “rested at next level” (where levels means days: this tree has number of level = number of days of the single caseTest) and on the right child of that node, it has the PRIZE of that level (day) summed.

At the end i only have to find the biggest number on level N.

Little thing: when dayLeft of a node is = 0, his right-child can not be created (becouse of the constraint on maximum days in a raw u can play), so i set it to 0 and DayLeft = R. In this way it SURELY not be the biggest at the end of the story !

Thank you so much, i’m on this problem since 1 week.

P.s. example for clarifing the idea: suppose N = 5, R = 2 and PRIZE ={ 9,5,7,1,8}

ROOT = 0 with DL (DayLeft) = 2

LEVEL 1: leftChild of root = 0 with 2 rightChild of root = 9 with DL = 1

LEVEL 2: leftCHild of leftChild of root = 0 with DL = 2, rightChild of LEftChild of Root = 5 with DL = 1

leftChild of rightChild of root =9 with DL = 1, rightChild of rightChild of Root = 5+9 = 14 with DL = 0

etc etc

i Hope it is clear… thanks to all !

Do you mean for Day 1 (level 1), you create 2 child nodes, for Day 2, you create 4 child nodes, and so on? If so, for the last test case where number of days = 365, you will create 2 ** 365 child nodes = a very large number of child nodes

Yes, too much right ? i couldnt came up with somethiing better for now… i dont know how to simplify the combinatoric of the system.

i tried to memo only the sums to wich the PRIZE could partecipate in, but still cant leave out a lot of combination

Have you tried thinking backwards? For example, using the example in the statement:

- What is the best prize I can get on Day 10 (by considering Day 10 only)?
- What is the best prize I can get on Day 9 (by considering Days 9 and 10 only)?
- What is the best prize I can get on Day 8 (by considering Days 8, 9 and 10 only)?

etc., up to the last question: - What is the best prize I can get on Day 1 (by considering all days)?

One can make use of the answers to earlier questions to work out the answers to later questions.

Thanks for the help, but i cant still figure it out. In this way don’t i still have to check ALL possibilities ?

Suppose R = 3.

The 1 number ofc i take it couse it maximize, the second idem, the 3 idem. At the 4 i have to rest (couse R = 3) but how can i know if this is the right combination ?

On Day 10 you have 2 possibilities:

• Rest: no prize

• Play: get prize of 2

=> Max prize is 2

On Day 9 you have these possibilities:

• Rest, then you are free to decide what to do on Day 10, so prize is 0 + 2 = 2

• Play, then you are free to decide what to do on Day 10, so prize is 2 + 2 = 4

=> Max prize is 4

And so on and so forth.

On Day 4, for example, you have these possibilities:

• Rest, then you are free to decide what to do on Day 5 and onwards, so prize = max prize you can get from Days 5 to 10

• Play for 1 day then rest, then you are free to decide what to do on Day 6 and onwards, so prize = Prize on Day 4 + max prize you can get from Days 6 to 10 (which has been calculated)

• Play for 2 days then rest, then you are free to decide what to do on Day 7 and onwards, so prize = Prizes on Days 4 and 5 + max prize you can get from Days 7 to 10 (which has been calculated)

• Play for 3 days then rest, then you are free to decide what to do on Day 8 and onwards, so prize = Prizes on Days 4 to 6 + max prize you can get from Days 8 to 10 (which has been calculated)

• Play for 4 days then rest, then you are free to decide what to do on Day 9 and onwards, so prize = Prizes on Days 4 to 7 + max prize you can get from Days 9 to 10 (which has been calculated)

Eventually you will get to Day 0, when you just have to choose the max prize you can get among the possibilities which you have calculated for Day 1.

At first glance you still seem to have to cover all possibilities, but actually you have skipped a lot of calculations because you can base your later answers on earlier calculations. If my understanding is correct, your original method is O(2^n) while the method described here is O(m x n).