Submission #1837648


Source Code Expand

# 再帰的に社員番号id番の社員の給与を求める関数
def calcSal(id, staff_info)

  return 1 if staff_info[id].empty? # 部下がいない社員の給与は1

  # id番の社員直属の部下の給与の配列を用意
  staff_sal = staff_info[id].map {|staff_id|
    calcSal(staff_id, staff_info)
  }

  # 直属の部下の給与配列のうち最大と最小を取り出す
  max = staff_sal.max
  min = staff_sal.min

  return sal = max + min + 1
end

n = gets.to_i
staff_info = []
staff_info[1] = []

# 社員番号1は高橋君、0回目には社員番号2の社員の上司情報が入力される
(n-1).times.map{|i|
  staff_info[i+2] = []
  boss = gets.to_i
  staff_info[boss] << i+2
}

p calcSal(1, staff_info);

Submission Info

Submission Time
Task C - 高橋君の給料
User nasmarl
Language Ruby (2.3.3)
Score 100
Code Size 767 Byte
Status AC
Exec Time 7 ms
Memory 1788 KB

Compile Error

./Main.rb:15: warning: assigned but unused variable - sal

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 4
AC × 22
Set Name Test Cases
Sample example_0.txt, example_1.txt, example_2.txt, example_3.txt
All example_0.txt, example_1.txt, example_2.txt, example_3.txt, maxrand_0.txt, maxrand_1.txt, maxrand_2.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, special_0.txt, example_0.txt, example_1.txt, example_2.txt, example_3.txt
Case Name Status Exec Time Memory
example_0.txt AC 7 ms 1788 KB
example_1.txt AC 7 ms 1788 KB
example_2.txt AC 7 ms 1788 KB
example_3.txt AC 7 ms 1788 KB
maxrand_0.txt AC 7 ms 1788 KB
maxrand_1.txt AC 7 ms 1788 KB
maxrand_2.txt AC 7 ms 1788 KB
random_0.txt AC 7 ms 1788 KB
random_1.txt AC 7 ms 1788 KB
random_2.txt AC 7 ms 1788 KB
random_3.txt AC 7 ms 1788 KB
random_4.txt AC 7 ms 1788 KB
random_5.txt AC 7 ms 1788 KB
random_6.txt AC 7 ms 1788 KB
random_7.txt AC 7 ms 1788 KB
random_8.txt AC 7 ms 1788 KB
random_9.txt AC 7 ms 1788 KB
special_0.txt AC 7 ms 1788 KB