Thanks to 競プロ同好会 IN Rails Girls More! https://scrapbox.io/rails-girls-kyopro-club/
https://atcoder.jp/contests/practice/tasks/practice_1
# hoge.rb
a = gets.chomp.to_i # ※gets.to_iではNG
b, c = gets.chomp.split.map(&:to_i)
s = gets.chomp
puts "#{a + b + c} #{s}" # 最後改行が必要(puts)
$ ruby hoge.rb (入力入れる)
puts gets.upcase
require 'debug'
binding.break
# 全探索する
(1..3).to_a.permutation.to_a
=> [[1,2,3],[1,3,2], [2,1,3],[2,3,1],[3,1,2],[3,2,1]]
# 共通の値を得る
["a", "b", "z"].intersection(["a", "b", "c"], ["b"]) # => ["b"]
n = gets.chomp.to_i s = gets.chomp # 文字列として値を1つ受け取る s = gets.chomp.chars # 文字列として値を受け取り、1文字ずつに分解する
n, m = gets.chomp.split.map(&:to_i)
array = gets.chomp.split.map(&:to_i)
n = gets.chomp.to_i array = [] n.times do array << gets.chomp.split.map(&:to_i) end
datas = Array.new(n+1) { Array.new(n+1) }
datas = Hash.new{|h,k| h[k] = {} }
total_precips = 0 cumu_precips = gets.chomp.split.map { |value| total_precips += value.to_i } cumu_precips.unshift 0
accを使うと良い
https://qiita.com/drken/items/4a7869c5e304883f539b
途中までの計算結果をキャッシュして利用するる
PriorityQueue
Ruby競プロTips(基本・罠・高速化108 2.7x2.7)
→ 超でかい素数として使われる
- 貰うDPと配るDP
- each より upto
- Infinityより整数
- Array.new( N, 0 )