Submission #70037161
Source Code Expand
function main(stdin) {
// eslint-disable-next-line unused-imports/no-unused-vars, no-unused-vars
const { next, nextstr, nextbig, nexts, nextssort, nextm, xArray } = makeInputReader(stdin)
const n = next()
function foo(num) {
let sum = 0
while (num !== 0) {
sum += num % 10
num = Math.floor(num / 10)
}
return sum
}
let res = 0
const arr = [1]
for (let i = 0; i < n; i++) {
res += foo(arr[i])
arr.push(res)
}
return res
}
function makeInputReader(input) {
const cin = input.trim().split(/ |\n/)
let cid = 0
function createNDArray(shape, fillFn) {
if (shape.length === 0)
return fillFn()
const [dim, ...rest] = shape
return Array.from({ length: dim }, () => createNDArray(rest, fillFn))
}
return {
next: () => Number(cin[cid++]),
nextstr: () => cin[cid++],
nextbig: () => BigInt(cin[cid++]),
nexts: (n, addNum = 0, parse = true) =>
parse ? cin.slice(cid, cid += n).map(s => Number(s) + addNum) : cin.slice(cid, cid += n),
nextssort: (n, parse = true, desc = false) =>
parse
? cin.slice(cid, cid += n).map(Number).sort((a, b) => desc ? b - a : a - b)
: cin.slice(cid, cid += n).sort((a, b) => desc ? b.localeCompare(a) : a.localeCompare(b)),
nextm: (h, w, parse = true) => {
const res = []
for (let i = 0; i < h; i++) {
const row = cin.slice(cid, cid += w)
res.push(parse ? row.map(Number) : row)
}
return res
},
xArray: createNDArray,
}
}
if (require.main === module) {
const fs = require('node:fs')
const input = fs.readFileSync('/dev/stdin', 'utf8')
console.log(main(input))
}
module.exports = { main }
Submission Info
| Submission Time |
|
| Task |
B - Sum of Digits Sequence |
| User |
xhksun |
| Language |
JavaScript (Node.js 18.16.1) |
| Score |
200 |
| Code Size |
1751 Byte |
| Status |
AC |
| Exec Time |
40 ms |
| Memory |
42756 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
200 / 200 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample00.txt, sample01.txt |
| All |
sample00.txt, sample01.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt |
| Case Name |
Status |
Exec Time |
Memory |
| sample00.txt |
AC |
39 ms |
42664 KiB |
| sample01.txt |
AC |
39 ms |
42752 KiB |
| testcase00.txt |
AC |
40 ms |
42556 KiB |
| testcase01.txt |
AC |
39 ms |
42664 KiB |
| testcase02.txt |
AC |
40 ms |
42668 KiB |
| testcase03.txt |
AC |
39 ms |
42752 KiB |
| testcase04.txt |
AC |
39 ms |
42704 KiB |
| testcase05.txt |
AC |
39 ms |
42688 KiB |
| testcase06.txt |
AC |
39 ms |
42640 KiB |
| testcase07.txt |
AC |
39 ms |
42676 KiB |
| testcase08.txt |
AC |
39 ms |
42568 KiB |
| testcase09.txt |
AC |
39 ms |
42696 KiB |
| testcase10.txt |
AC |
39 ms |
42756 KiB |
| testcase11.txt |
AC |
39 ms |
42752 KiB |