結果

問題 No.774 tatyamと素数大富豪
ユーザー finefine
提出日時 2018-12-22 20:08:32
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 505 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 11,976 KB
実行使用メモリ 18,464 KB
最終ジャッジ日時 2023-10-26 02:10:54
合計ジャッジ時間 3,420 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
16,400 KB
testcase_01 AC 108 ms
16,388 KB
testcase_02 AC 99 ms
16,388 KB
testcase_03 AC 98 ms
16,388 KB
testcase_04 WA -
testcase_05 AC 99 ms
16,400 KB
testcase_06 AC 98 ms
16,388 KB
testcase_07 WA -
testcase_08 AC 99 ms
16,388 KB
testcase_09 AC 99 ms
16,388 KB
testcase_10 AC 178 ms
18,464 KB
testcase_11 AC 100 ms
16,404 KB
testcase_12 WA -
testcase_13 AC 99 ms
16,400 KB
testcase_14 AC 101 ms
16,388 KB
testcase_15 AC 100 ms
16,400 KB
testcase_16 AC 457 ms
18,464 KB
testcase_17 WA -
testcase_18 AC 101 ms
16,608 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

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