結果

問題 No.1237 EXP Multiple!
ユーザー gemmarogemmaro
提出日時 2020-10-09 06:26:19
言語 Ruby
(3.3.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 352 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 11,344 KB
実行使用メモリ 30,028 KB
最終ジャッジ日時 2023-09-27 12:30:54
合計ジャッジ時間 4,718 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
15,140 KB
testcase_01 AC 141 ms
24,744 KB
testcase_02 AC 159 ms
28,092 KB
testcase_03 AC 157 ms
28,476 KB
testcase_04 AC 162 ms
28,864 KB
testcase_05 AC 137 ms
27,048 KB
testcase_06 AC 149 ms
26,932 KB
testcase_07 AC 132 ms
26,944 KB
testcase_08 AC 250 ms
30,028 KB
testcase_09 AC 133 ms
26,828 KB
testcase_10 AC 130 ms
26,896 KB
testcase_11 AC 149 ms
26,820 KB
testcase_12 AC 148 ms
26,840 KB
testcase_13 AC 247 ms
29,676 KB
testcase_14 AC 254 ms
29,952 KB
testcase_15 AC 249 ms
29,732 KB
testcase_16 AC 249 ms
29,840 KB
testcase_17 AC 244 ms
29,852 KB
testcase_18 AC 248 ms
29,736 KB
testcase_19 AC 148 ms
27,116 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

L = 10**9 + 7

class Integer
  def fact
    (1..self).reduce(:*)
  end
end

def solve
  if A.any?(&:zero?)
    -1
  elsif A.max >= 4
    L
  else
    L % (A.reduce(1) do |result, item|
      x = result * item**item.fact
      x > L ? (return L) : x
    end)
  end
end

N = gets.to_i
A = gets.split.map(&:to_i)
puts solve
0