結果
| 問題 | No.12 限定された素数 |
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-08-31 10:54:23 |
| 言語 | Kotlin (2.3.20) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,764 bytes |
| 記録 | |
| コンパイル時間 | 15,244 ms |
| コンパイル使用メモリ | 486,604 KB |
| 実行使用メモリ | 137,084 KB |
| 最終ジャッジ日時 | 2026-05-18 03:58:53 |
| 合計ジャッジ時間 | 50,217 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 7 |
ソースコード
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 numberMap = mutableMapOf<Int, Int>()
var stattIndex = 0
var ans = 0
for(i in primeList.indices) {
primeList[i].toString().map { it.toString().toInt() }.forEach {
val key = it
numberMap[key]?.also { numberMap[key] = it+1 } ?: run { numberMap[key] = 1 }
}
while (numberMap.filter { it.value > 0 }.any { !numberList.contains(it.key) }) {
primeList[stattIndex].toString().map { it.toString().toInt() }.forEach { numberMap[it] = numberMap[it]!!-1 }
stattIndex++
}
if(!numberMap.filter { it.value > 0 }.all { numberList.contains(it.key) }) {
stattIndex = i + 1
}
if(stattIndex <= i) {
var startNum = 0
if(stattIndex == 0) {
startNum = 1
} else {
startNum = 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
}
バカらっく