Submission #70985017
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, x, y] = nexts(3)
const A = nexts(n)
const d = y - x
const R = BigInt(A[0] * x) % BigInt(d)
// for (const a of A) {
// if (BigInt(a * x) % BigInt(d) !== R)
// return -1
// }
let prev = -1
for (let i = 0; i < n - 1; i++) {
const D = Math.max(A[i + 1], A[i]) - Math.min(A[i + 1], A[i])
if (prev === -1) {
prev = D % d
}
else if (prev !== D % d) {
return -1
}
}
const WMAX = BigInt(Math.min(...A)) * BigInt(y)
const WMIN = BigInt(Math.max(...A)) * BigInt(x)
const adjust = (WMAX - R) % BigInt(d)
const w = WMAX - adjust
if (w < WMIN) {
return -1
}
let res = 0n
for (const a of A) {
const l = (BigInt(w) - BigInt(a * x)) / BigInt(d)
if (l > BigInt(a)) {
return -1
}
res += l
}
return res.toString()
}
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 | C - Candy Tribulation |
| User | xhksun |
| Language | JavaScript (Node.js 22.19.0) |
| Score | 0 |
| Code Size | 2296 Byte |
| Status | WA |
| Exec Time | 108 ms |
| Memory | 83148 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 350 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 43 ms | 42068 KiB |
| 00-sample-02.txt | AC | 23 ms | 42068 KiB |
| 00-sample-03.txt | AC | 22 ms | 41996 KiB |
| 01-01.txt | AC | 108 ms | 58704 KiB |
| 01-02.txt | AC | 30 ms | 51324 KiB |
| 01-03.txt | AC | 45 ms | 59912 KiB |
| 01-04.txt | AC | 46 ms | 60192 KiB |
| 01-05.txt | AC | 74 ms | 77012 KiB |
| 01-06.txt | AC | 86 ms | 83148 KiB |
| 01-07.txt | AC | 86 ms | 83008 KiB |
| 01-08.txt | AC | 84 ms | 82932 KiB |
| 01-09.txt | AC | 85 ms | 83036 KiB |
| 01-10.txt | AC | 87 ms | 83028 KiB |
| 01-11.txt | AC | 68 ms | 73196 KiB |
| 01-12.txt | AC | 66 ms | 73288 KiB |
| 01-13.txt | AC | 75 ms | 77448 KiB |
| 01-14.txt | WA | 60 ms | 71204 KiB |
| 01-15.txt | AC | 60 ms | 71280 KiB |
| 01-16.txt | AC | 84 ms | 81772 KiB |
| 01-17.txt | WA | 60 ms | 71396 KiB |
| 01-18.txt | WA | 60 ms | 71320 KiB |
| 01-19.txt | WA | 56 ms | 68404 KiB |
| 01-20.txt | WA | 60 ms | 71248 KiB |
| 01-21.txt | WA | 60 ms | 71320 KiB |
| 01-22.txt | AC | 64 ms | 71744 KiB |
| 01-23.txt | AC | 61 ms | 71332 KiB |
| 01-24.txt | AC | 60 ms | 71300 KiB |
| 01-25.txt | AC | 54 ms | 64520 KiB |
| 01-26.txt | AC | 42 ms | 60384 KiB |
| 01-27.txt | AC | 50 ms | 64796 KiB |
| 01-28.txt | WA | 47 ms | 61044 KiB |
| 01-29.txt | AC | 59 ms | 71440 KiB |
| 01-30.txt | AC | 60 ms | 71284 KiB |
| 01-31.txt | AC | 70 ms | 76072 KiB |
| 01-32.txt | WA | 60 ms | 71304 KiB |
| 01-33.txt | WA | 60 ms | 71356 KiB |
| 01-34.txt | WA | 49 ms | 61524 KiB |
| 01-35.txt | WA | 60 ms | 71332 KiB |
| 01-36.txt | WA | 60 ms | 71340 KiB |
| 01-37.txt | AC | 43 ms | 60304 KiB |
| 01-38.txt | AC | 60 ms | 71344 KiB |
| 01-39.txt | AC | 60 ms | 71416 KiB |
| 01-40.txt | AC | 51 ms | 64188 KiB |
| 01-41.txt | AC | 48 ms | 61164 KiB |
| 01-42.txt | AC | 43 ms | 60676 KiB |
| 01-43.txt | AC | 60 ms | 70700 KiB |