結果
| 問題 |
No.12 限定された素数
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-08-31 11:12:39 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,775 bytes |
| コンパイル時間 | 18,404 ms |
| コンパイル使用メモリ | 446,684 KB |
| 実行使用メモリ | 160,600 KB |
| 最終ジャッジ日時 | 2024-11-24 06:16:21 |
| 合計ジャッジ時間 | 59,823 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 WA * 24 |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args: Array<String>){
^
Main.kt:4:9: warning: variable 'numberCount' is never used
val numberCount = readLine()!!.toInt()
^
Main.kt:24:28: warning: variable 'startNum' initializer is redundant
var startNum = 0
^
ソースコード
import kotlin.math.max
fun main(args: Array<String>){
val numberCount = readLine()!!.toInt()
val numberList = readLine()!!.trim().split(" ").map { it.toInt() }
val primeList = getPrimeList()
val primeSplitedList = primeList.map { it.toString().map { it.toString().toInt() } }
val numberMap = mutableMapOf<Int, Int>()
(0..9).forEach{numberMap[it] = 0}
var stattIndex = 0
var ans = 0
for(i in primeList.indices) {
primeSplitedList[i].forEach {numberMap[it] = numberMap[it]!! + 1}
while (numberMap.filter { it.value > 0 }.keys.any { !numberList.contains(it) }) {
primeSplitedList[stattIndex].forEach { numberMap[it] = numberMap[it]!!-1 }
stattIndex++
}
if(!numberList.all { numberMap.filter { it.value > 0 }.keys.contains(i) }) {
stattIndex = i + 1
(0..9).forEach { numberMap[it] = 0 }
}
if(stattIndex <= i) {
var startNum = 0
startNum = if(stattIndex == 0) {
1
} else {
primeList[stattIndex-1] + 1
}
var endNum = 5000000
if(i < primeList.lastIndex) {
endNum = primeList[i + 1] - 1
}
ans = Math.max(ans, endNum - startNum)
}
}
if(ans == 0) {
ans = -1
}
println(ans)
}
fun getPrimeList():List<Int> {
val max = 5000000
val primeList = mutableListOf<Int>()
val flags = arrayOfNulls<Boolean>(max + 1)
for(i in 2..max) {
if(flags[i] != null && flags[i]!!) {
continue
}
val maxIndex = max / i
for(j in 1..maxIndex) {
flags[i * j] = true
}
primeList.add(i)
}
return primeList
}
バカらっく