結果
| 問題 | No.732 3PrimeCounting |
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2017-01-22 15:17:25 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 894 bytes |
| 記録 | |
| コンパイル時間 | 43 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 28,544 KB |
| 最終ジャッジ日時 | 2024-12-23 05:30:22 |
| 合計ジャッジ時間 | 119,235 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 66 TLE * 23 |
コンパイルメッセージ
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
ソースコード
#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)
startcpp