結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー 👑 箱
提出日時 2022-08-05 21:42:10
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 483 ms / 2,000 ms
コード長 1,026 bytes
コンパイル時間 15,599 ms
コンパイル使用メモリ 425,948 KB
実行使用メモリ 62,600 KB
最終ジャッジ日時 2023-10-13 22:19:43
合計ジャッジ時間 30,414 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 298 ms
55,060 KB
testcase_01 AC 293 ms
55,060 KB
testcase_02 AC 469 ms
62,600 KB
testcase_03 AC 299 ms
53,008 KB
testcase_04 AC 476 ms
61,036 KB
testcase_05 AC 467 ms
60,648 KB
testcase_06 AC 468 ms
60,816 KB
testcase_07 AC 409 ms
58,404 KB
testcase_08 AC 483 ms
62,596 KB
testcase_09 AC 389 ms
55,772 KB
testcase_10 AC 437 ms
56,980 KB
testcase_11 AC 402 ms
56,948 KB
testcase_12 AC 437 ms
56,688 KB
testcase_13 AC 409 ms
56,428 KB
testcase_14 AC 395 ms
58,260 KB
testcase_15 AC 428 ms
56,836 KB
testcase_16 AC 424 ms
56,448 KB
testcase_17 AC 305 ms
53,196 KB
testcase_18 AC 302 ms
53,264 KB
testcase_19 AC 302 ms
53,260 KB
testcase_20 AC 305 ms
54,964 KB
testcase_21 AC 306 ms
55,116 KB
testcase_22 AC 445 ms
58,628 KB
testcase_23 AC 419 ms
56,516 KB
testcase_24 AC 377 ms
56,796 KB
testcase_25 AC 455 ms
62,532 KB
testcase_26 AC 403 ms
58,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    var s = nextLong()
    val lst = mutableListOf<Int>()
    for (i in n downTo 1) {
        if (s >= i) {
            s -= i
            lst.add(i)
        }
    }
    println(lst.size)
    println(lst.reversed().joinToString(" "))
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

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()
// endregion
0