結果

問題 No.1006 Share an Integer
ユーザー 👑 箱星箱星
提出日時 2020-03-06 21:57:21
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,542 bytes
コンパイル時間 17,093 ms
コンパイル使用メモリ 450,264 KB
実行使用メモリ 89,464 KB
最終ジャッジ日時 2024-04-22 07:29:48
合計ジャッジ時間 22,892 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:7:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:41:12: warning: 'appendln(String?): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
        sb.appendln("%d %d".format(item.first, item.second))
           ^

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.StringBuilder
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val x = sc.nextInt()
    val count = Array(x) { 0 }
    for (n in 1 until x) {
        var d = 1
        while (d * d <= n) {
            if (n % d == 0) {
                if (d * d != n) {
                    count[n] += 2
                } else {
                    count[n] += 1
                }
            }
            d++
        }
    }
    var min = Int.MAX_VALUE
    val ans = mutableListOf<Pair<Int, Int>>()
    for (a in 1..x / 2) {
        val b = x - a
        val v = Math.abs((a - count[a]) - (b - count[b]))
        if (min > v) {
            min = v
            ans.clear()
        }
        if (min == v) {
            ans.add(a to b)
            ans.add(b to a)
        }
    }
    ans.sortBy { it.first }
    val sb = StringBuilder()
    for (item in ans) {
        sb.appendln("%d %d".format(item.first, item.second))
    }
    println(sb.toString())
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}
0