Thanks for all the suggestions. I've finally managed to solve the problem 
for Test set 1, using the real inputs downloaded from under the analysis. 
Great hint! The RE error was caused by the line *return 
Math.max(...permsMaxes); *- it was too resource-consuming. I've resolved 
this issue by modyfing the excerpt like this: 

*let permsMaxesSet = new Set(permsMaxes);*
*return Math.max(...permsMaxesSet);*

Now I will have to solve the problem for the other test sets (another RE 
caused by the permutation section - it is too resource-consuming), but your 
help was really important!

Thanks again!
środa, 6 kwietnia 2022 o 17:11:47 UTC+2 porker2008 napisał(a):

> Maybe consider the worst case where N = 10, and all of them are not 
> pointing anywhere
>
>
>
>
> *11060 20 40 50 60 20 40 50 60 200 0 0 0 0 0 0 0 0 0*
>
> 在2022年4月5日星期二 UTC-7 17:27:24<jawa> 写道:
>
>> Hello plesse send one test case where it is failing
>>
>> https://codingcompetitions.withgoogle.com/codejam/round/0000000000876ff1/0000000000a45ef7
>>
>> On Mon, 4 Apr 2022, 20:16 DarkDogg92, <kuba...@gmail.com> wrote:
>>
>>> Hello everybody,
>>>
>>> I can't manage to solve the Chain Reactions problem. My solution seems 
>>> to work locally, passes the sample tests on site, but when it comes to the 
>>> real tests, I always get a runtime error.
>>>
>>> I decided to build a graph for every test case, then generate all the 
>>> permutations of the chain reaction initiators and traverse the graph in 
>>> order relevant for each permutation.
>>>
>>> I used a similar general code structure for other problems and it 
>>> worked, so I guess it is a problem with the solution's logic.
>>>
>>> Below is my code in JS.
>>> Any suggestions would be greately appreciated!
>>>
>>>
>>>
>>> 'use strict';
>>>
>>> var readline = require('readline');
>>> var rl = readline.createInterface({
>>>     input: process.stdin,
>>>     output: process.stdout,
>>> });
>>>
>>> class NodeF {
>>>     constructor(f) {
>>>         this.back = false;
>>>         this.used = false;
>>>         this.f = f;
>>>     }
>>> }
>>>
>>> class Input {
>>>     constructor(strings) {
>>>         this.stringsInd = 0;
>>>         this.strings = strings;
>>>     }
>>>     getString() {
>>>         return this.strings[this.stringsInd++];
>>>     }
>>>     getStringArray(sep) {
>>>         return this.getString().split(sep);
>>>     }
>>>     getNumber() {
>>>         return parseInt(this.getString());
>>>     }
>>>     getNumberArray(sep) {
>>>         return this.getStringArray(sep).map(a => parseInt(a));
>>>     }
>>> }
>>>
>>> let permutatorMethod = (inpArr) => {
>>>     let res = [];
>>>     let doPermute = (array, g) => {
>>>         if (array.length === 0) {
>>>             res.push(g);
>>>         }
>>>         else {
>>>             for (let x = 0; x < array.length; x++) {
>>>                 let current = array.slice();
>>>                 let next = current.splice(x, 1);
>>>                 doPermute(current.slice(), g.concat(next));
>>>             }
>>>         }
>>>     };
>>>     doPermute(inpArr, []);
>>>     return res;
>>> };
>>>
>>> let clearTree = (nodes) => {
>>>     nodes.forEach((node) => {
>>>         node.used = false;
>>>     });
>>> };
>>>
>>> let solve = (input) => {
>>>     let n = input.getNumber();
>>>     let fss = input.getNumberArray(' ');
>>>     let pss = input.getNumberArray(' ');
>>>     let nodes = [];
>>>     for (let i = 0; i < fss.length; i++) {
>>>         nodes.push(new NodeF(fss[i]));
>>>     }
>>>     for (let i = 0; i < pss.length; i++) {
>>>         if (pss[i] === 0) {
>>>             nodes[i].next = null;
>>>         }
>>>         else {
>>>             nodes[i].next = nodes[pss[i] - 1];
>>>             nodes[pss[i] - 1].back = true;
>>>         }
>>>     }
>>>     let nodeInitiators = nodes.filter(x => x.back === false);
>>>     let nodeInitiatorsPerms = permutatorMethod(nodeInitiators);
>>>     let permsMaxes = [];
>>>     nodeInitiatorsPerms.forEach((perm) => {
>>>         clearTree(nodes);
>>>         let maxSum = 0;
>>>         perm.forEach((ni) => {
>>>             let max = 0;
>>>             while (ni !== null && ni.used !== true) {
>>>                 max = Math.max(ni.f, max);
>>>                 ni.used = true;
>>>                 ni = ni.next;
>>>             }
>>>             maxSum += max;
>>>         });
>>>         permsMaxes.push(maxSum);
>>>     });
>>>     return Math.max(...permsMaxes);
>>> };
>>>
>>>
>>> let main = (input) => {
>>>     let _numTests = input.getNumber();
>>>     for (let _id = 1; _id <= _numTests; ++_id) {
>>>         console.log('Case #' + _id + ': ' + solve(input));
>>>     }
>>> };
>>>
>>> function init() {
>>>     let strings = [];
>>>     rl.on('line', function (line) {
>>>         strings.push(line);
>>>     }).on('close', function () {
>>>         main(new Input(strings));
>>>         process.exit(0);
>>>     });
>>> }
>>> if (!module.parent) {
>>>     init();
>>> }
>>> //# sourceMappingURL=index.js.map
>>>
>>> -- 
>>> -- You received this message because you are subscribed to the Google 
>>> Groups Code Jam group. To post to this group, send email to 
>>> googl...@googlegroups.com. To unsubscribe from this group, send email 
>>> to google-code...@googlegroups.com. For more options, visit this group 
>>> at https://groups.google.com/d/forum/google-code?hl=en
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Google Code Jam" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to google-code...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/google-code/bbff8533-ad73-4b9d-8a72-6794831df987n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/google-code/bbff8533-ad73-4b9d-8a72-6794831df987n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
-- You received this message because you are subscribed to the Google Groups 
Code Jam group. To post to this group, send email to 
google-code@googlegroups.com. To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com. For more options, visit this group at 
https://groups.google.com/d/forum/google-code?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/223549c8-3e22-42a2-a804-49380868e87en%40googlegroups.com.

Reply via email to