Last active
July 13, 2023 12:42
-
-
Save omas-public/055f67b4e76c1bcf3bd5a9e1d0c80320 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stream = require('fs').readFileSync('/dev/stdin', 'utf8').trim() | |
const cols = stream.split(' ') | |
const lines = stream.split('\n') | |
const matrix = lines.map(line => line.split(' ')) | |
const fn = (N, C, matrix) => { | |
const f = (acc, [n, c]) => [ | |
...acc.slice(0, n - 1), c, ...acc.slice(n) | |
] | |
const pairs = matrix.map(([n, c]) => [Number(n), c]) | |
return pairs.reduce(f, Array(Number(N)).fill(C)).join('') | |
} | |
const [[N], , ...rest] = matrix | |
const [ns, [C]] = [rest.slice(0, -1), rest.at(-1)] | |
const result = fn(N, C, ns) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment