結果

問題 No.774 tatyamと素数大富豪
ユーザー finefine
提出日時 2018-12-22 20:09:31
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 509 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 11,980 KB
実行使用メモリ 36,336 KB
最終ジャッジ日時 2023-10-26 02:11:07
合計ジャッジ時間 9,675 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,640 ms
36,336 KB
testcase_01 AC 101 ms
16,388 KB
testcase_02 AC 101 ms
16,388 KB
testcase_03 AC 110 ms
16,968 KB
testcase_04 AC 102 ms
16,388 KB
testcase_05 AC 102 ms
16,400 KB
testcase_06 AC 100 ms
16,388 KB
testcase_07 WA -
testcase_08 AC 101 ms
16,392 KB
testcase_09 AC 102 ms
16,388 KB
testcase_10 AC 447 ms
18,464 KB
testcase_11 AC 461 ms
18,464 KB
testcase_12 AC 978 ms
27,532 KB
testcase_13 AC 836 ms
27,560 KB
testcase_14 AC 102 ms
16,388 KB
testcase_15 AC 466 ms
18,464 KB
testcase_16 AC 457 ms
18,464 KB
testcase_17 AC 448 ms
18,016 KB
testcase_18 AC 458 ms
18,464 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 > ans ? x : ans)
    end
end
p ans
0