結果

問題 No.732 3PrimeCounting
ユーザー startcppstartcpp
提出日時 2017-01-22 15:17:25
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 894 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 11,420 KB
実行使用メモリ 22,368 KB
最終ジャッジ日時 2023-08-24 19:59:57
合計ジャッジ時間 12,736 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
19,728 KB
testcase_01 AC 79 ms
15,156 KB
testcase_02 AC 79 ms
15,128 KB
testcase_03 AC 78 ms
15,144 KB
testcase_04 AC 79 ms
15,288 KB
testcase_05 AC 77 ms
15,124 KB
testcase_06 AC 78 ms
15,268 KB
testcase_07 AC 77 ms
15,276 KB
testcase_08 AC 76 ms
15,160 KB
testcase_09 AC 77 ms
15,140 KB
testcase_10 AC 77 ms
15,144 KB
testcase_11 AC 77 ms
15,248 KB
testcase_12 AC 77 ms
15,140 KB
testcase_13 AC 77 ms
15,144 KB
testcase_14 AC 77 ms
15,128 KB
testcase_15 AC 77 ms
15,144 KB
testcase_16 AC 77 ms
15,128 KB
testcase_17 AC 78 ms
15,160 KB
testcase_18 AC 78 ms
15,152 KB
testcase_19 AC 77 ms
15,284 KB
testcase_20 AC 82 ms
15,332 KB
testcase_21 AC 116 ms
15,524 KB
testcase_22 AC 115 ms
15,104 KB
testcase_23 AC 79 ms
15,164 KB
testcase_24 AC 79 ms
15,040 KB
testcase_25 AC 192 ms
15,568 KB
testcase_26 AC 142 ms
15,596 KB
testcase_27 AC 86 ms
15,284 KB
testcase_28 AC 85 ms
15,156 KB
testcase_29 AC 103 ms
15,336 KB
testcase_30 AC 103 ms
15,192 KB
testcase_31 AC 122 ms
15,396 KB
testcase_32 AC 156 ms
15,552 KB
testcase_33 AC 157 ms
15,384 KB
testcase_34 AC 159 ms
15,404 KB
testcase_35 AC 130 ms
15,508 KB
testcase_36 AC 129 ms
15,628 KB
testcase_37 AC 79 ms
15,124 KB
testcase_38 AC 79 ms
15,100 KB
testcase_39 AC 133 ms
15,380 KB
testcase_40 AC 126 ms
15,504 KB
testcase_41 AC 124 ms
15,468 KB
testcase_42 AC 125 ms
15,552 KB
testcase_43 AC 108 ms
15,156 KB
testcase_44 AC 108 ms
15,228 KB
testcase_45 AC 88 ms
15,300 KB
testcase_46 AC 89 ms
15,292 KB
testcase_47 AC 93 ms
15,104 KB
testcase_48 AC 206 ms
15,536 KB
testcase_49 AC 205 ms
15,396 KB
testcase_50 AC 115 ms
15,204 KB
testcase_51 AC 116 ms
15,412 KB
testcase_52 AC 87 ms
15,300 KB
testcase_53 AC 507 ms
15,808 KB
testcase_54 TLE -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:4: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
Main.rb:26: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
Syntax OK

ソースコード

diff #

#rubyの引数, 代入は参照渡し. 参照透明性とは何だったのか…
#このコードは定数倍が重いのでTLEします

def setPrime (is_prime, primes, n)
	for i in 2..n do
		is_prime[i] = true
	end
	
	for i in 2..n do
		if is_prime[i] then
			j = 2 * i
			while j <= n do
				is_prime[j] = false
				j += i
			end
		end
	end
	
	for i in 2..n do
		if is_prime[i] then
			primes.push(i);
		end
	end
end

def initCnts (cnts, n)
	for i in 0..n do
		cnts[i] = 0
	end
end

#ここからmain
n = STDIN.gets.chop.to_i

is_prime = Array.new
primes   = Array.new
cnts     = Array.new

setPrime(is_prime, primes, 3 * n)
initCnts(cnts, 3 * n)

ans = 0

for c in primes do
	if (c > n) then
		break
	end
	
	for sum in primes do
		if sum <= c then
			next
		end
		
		ans += cnts[sum - c]
	end
	
	for a in primes do
		if a >= c then
			break
		end
		
		cnts[a + c] += 1
	end
end

puts(ans)
0