結果
問題 | No.90 品物の並び替え |
ユーザー |
![]() |
提出日時 | 2020-09-02 21:31:08 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 530 ms / 5,000 ms |
コード長 | 1,179 bytes |
コンパイル時間 | 14,236 ms |
コンパイル使用メモリ | 446,912 KB |
実行使用メモリ | 52,460 KB |
最終ジャッジ日時 | 2024-11-21 21:36:27 |
合計ジャッジ時間 | 18,780 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
コンパイルメッセージ
Main.kt:29:13: warning: 'appendln(Int): 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. builder.appendln(maxScore) ^
ソースコード
import kotlin.math.maxfun main() {val builder = StringBuilder()val (n, m) = readInputLine().split(" ").map { it.toInt() }val scores = Array(m) {val (i1, i2, s) = readInputLine().split(" ").map { it.toInt() }Triple(i1, i2, s)}val arr = IntArray(n) { it }var maxScore = 0do {var tmp = 0for (s in scores) {if (arr[s.first] < arr[s.second]) {tmp += s.third}}maxScore = max(maxScore, tmp)} while (nextPermutation(arr))builder.appendln(maxScore)print(builder.toString())}fun readInputLine(): String {return readLine()!!}fun nextPermutation(arr: IntArray): Boolean {var i = arr.size - 1while (i > 0 && arr[i - 1] >= arr[i]) {i--}if (i <= 0) {return false}var j = arr.size - 1while (arr[j] <= arr[i - 1]) {j--}var temp = arr[i - 1];arr[i - 1] = arr[j];arr[j] = temp;j = arr.size - 1;while (i < j) {temp = arr[i];arr[i] = arr[j];arr[j] = temp;i++;j--;}return true;}