結果

問題 No.774 tatyamと素数大富豪
コンテスト
ユーザー fine
提出日時 2018-12-22 20:08:32
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 505 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 263 ms
コンパイル使用メモリ 9,088 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2026-04-12 14:44:09
合計ジャッジ時間 2,419 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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

ソースコード

diff #
raw source code

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
0