結果
| 問題 |
No.774 tatyamと素数大富豪
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-22 20:08:32 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 505 bytes |
| コンパイル時間 | 72 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 13,952 KB |
| 最終ジャッジ日時 | 2024-09-25 10:15:28 |
| 合計ジャッジ時間 | 3,458 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 11 WA * 3 |
コンパイルメッセージ
Main.rb:16: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:19: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
require 'prime'
require 'set'
def calc(a)
sum = 0
a.each do |s|
sum += s.split('').map(&:to_i).inject(:+)
end
return sum
end
n = gets.to_i
arr = gets.chomp.split
if arr.uniq.size == 1
p -1
exit
elsif calc(arr) % 3 == 0 && !(n == 1 && arr[0].to_i == 3)
p -1
exit
end
ans = -1
s = Set.new()
arr.sort!.reverse!
arr.permutation(n) do |a|
x = a.join.to_i
if s.add?(x).nil?
next
end
if x.prime?
ans = x
break
end
end
p ans