Last active
August 29, 2015 14:10
-
-
Save parrot-studio/eb55972db9ff3852f9d7 to your computer and use it in GitHub Desktop.
This file contains 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
https://paiza.jp/poh/enkoi | |
Ruby / CoffeeScript |
This file contains 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
process.stdin.resume() | |
process.stdin.setEncoding 'utf-8' | |
process.stdin.on 'data', (chunk) -> | |
lines = chunk.toString().split('\n') | |
size = parseInt lines.shift() | |
all = 0 | |
for n in lines[0..(size-1)] | |
all += parseInt n | |
console.log all |
This file contains 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
size = gets.to_i | |
all = 0 | |
size.times do | |
all += gets.to_i | |
end | |
puts all |
This file contains 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
process.stdin.resume() | |
process.stdin.setEncoding 'utf-8' | |
process.stdin.on 'data', (chunk) -> | |
lines = chunk.toString().split('\n') | |
size = parseInt lines.shift() | |
all = 0 | |
for l in lines[0..(size-1)] | |
ds = l.toString().split(' ') | |
need = (parseInt ds[0]) - (parseInt ds[1]) | |
continue if need <= 0 | |
all += (parseInt ds[2]) * need | |
console.log all |
This file contains 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
size = gets.to_i | |
all = 0 | |
size.times do | |
ds = gets.split(' ').map(&:to_i) | |
need = ds[0] - ds[1] | |
next if need <= 0 | |
all += ds[2] * need | |
end | |
puts all |
This file contains 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
# テストは通るのにTaseCase4でエラー | |
process.stdin.resume() | |
process.stdin.setEncoding 'utf-8' | |
process.stdin.on 'data', (chunk) -> | |
lines = chunk.toString().split('\n') | |
ps = lines.shift().toString().split(' ') | |
size = parseInt ps[0] | |
len = parseInt ps[1] | |
now = 0 | |
buf = [] | |
for l in lines[0..(size-1)] | |
num = parseInt l | |
now += num | |
buf.push num | |
max = now | |
for l in lines[size..len-1] | |
num = parseInt l | |
now += (num - buf.shift()) | |
max = now if now > max | |
buf.push num | |
console.log max |
This file contains 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
size, len = gets.split(' ').map(&:to_i) | |
now = 0 | |
buf = [] | |
size.times do | |
num = gets.to_i | |
now += num | |
buf << num | |
end | |
max = now | |
(len-size).times do | |
num = gets.to_i | |
now += (num - buf.shift) | |
max = now if now > max | |
buf << num | |
end | |
puts max |
rev:eb5597 => https://paiza.jp/poh/enkoi-ending/290aaac9
TestCase7 : 0.43s => OK
rev:3b0955 => https://paiza.jp/poh/enkoi-ending/9e0466d1
いらない変数を削ったけど、誤差の範囲
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rev:172707 => https://paiza.jp/poh/enkoi-ending/19d94a16