Skip to content

Commit be8ab4e

Browse files
committed
Solve 2896, 5430, and 14585
1 parent e687d03 commit be8ab4e

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

P14585.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const readline = require('readline')
2+
const interface = readline.createInterface(process.stdin)
3+
4+
interface.once('line', line => {
5+
const candy_count = Number(line.split(' ')[1])
6+
const baskets = new Set()
7+
interface.on('line', line => {
8+
let [x, y] = line.split(' ').map(Number)
9+
baskets.add(y * 301 + x)
10+
}).on('close', () => {
11+
let max_candy = Array.from({ length: 301 * 301 })
12+
max_candy[0] = 0
13+
for (let x = 1; x < 301; ++x) {
14+
max_candy[x] = max_candy[x - 1]
15+
if (baskets.has(x)) {
16+
max_candy[x] += Math.max(0, candy_count - x)
17+
}
18+
}
19+
for (let y = 1; y < 301; ++y) {
20+
max_candy[y * 301] = max_candy[y * 301 - 301]
21+
if (baskets.has(y * 301)) {
22+
max_candy[y * 301] += Math.max(0, candy_count - y)
23+
}
24+
}
25+
let max = 0
26+
for (let y = 1; y < 301; ++y) {
27+
for (let x = 1; x < 301; ++x) {
28+
max_candy[y * 301 + x] = Math.max(max_candy[y * 301 - 301 + x], max_candy[y * 301 + x - 1])
29+
if (baskets.has(y * 301 + x)) {
30+
max_candy[y * 301 + x] += Math.max(0, candy_count - x - y)
31+
}
32+
if (max_candy[y * 301 + x] > max) {
33+
max = max_candy[y * 301 + x]
34+
}
35+
}
36+
}
37+
console.log(max)
38+
})
39+
})

P2896.f95

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
program P2896
2+
implicit none
3+
real :: orange, apple, pine
4+
real :: i, j, k
5+
integer :: it, max
6+
7+
real, dimension(3, 4) :: result
8+
9+
read (*, *) orange, apple, pine
10+
read (*, *) i, j, k
11+
12+
result(1, 1) = 0
13+
result(1, 2) = apple - orange * j / i
14+
result(1, 3) = pine - orange * k / i
15+
result(1, 4) = orange / i
16+
17+
result(2, 1) = orange - apple * i / j
18+
result(2, 2) = 0
19+
result(2, 3) = pine - apple * k / j
20+
result(2, 4) = apple / j
21+
22+
result(3, 1) = orange - pine * i / k
23+
result(3, 2) = apple - pine * j / k
24+
result(3, 3) = 0
25+
result(3, 4) = pine / k
26+
27+
max = 1
28+
do it = 1, 3
29+
if (result(it, 1) < 0 .or. result(it, 2) < 0 .or. result(it, 3) < 0) then
30+
result(it, 4) = 0
31+
end if
32+
if (result(max, 4) < result(it, 4)) then
33+
max = it
34+
end if
35+
end do
36+
37+
write (*, *) result(max, 1), result(max, 2), result(max, 3)
38+
end program P2896

P5430.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const readline = require('readline')
2+
const interface = readline.createInterface(process.stdin)
3+
let line_index = 0
4+
let actions, count
5+
let left, right
6+
let reversed
7+
interface.once('line', () => interface.on('line', line => {
8+
switch (line_index % 3) {
9+
case 0:
10+
actions = line
11+
break
12+
case 1:
13+
count = Number(line)
14+
left = 0
15+
right = count
16+
reversed = false
17+
for (const action of actions) {
18+
if (action === 'R') {
19+
reversed = !reversed
20+
} else if (reversed) {
21+
right -= 1
22+
} else {
23+
left += 1
24+
}
25+
}
26+
break
27+
case 2:
28+
if (left > right) {
29+
console.log('error')
30+
} else {
31+
const numbers = line.slice(1, line.length - 1).split(',').slice(left, right)
32+
if (reversed) {
33+
numbers.reverse()
34+
}
35+
console.log('[' + numbers.join(',') + ']')
36+
}
37+
break
38+
}
39+
line_index += 1
40+
}))

0 commit comments

Comments
 (0)