結果
問題 |
No.607 開通777年記念
|
ユーザー |
|
提出日時 | 2022-10-08 23:23:49 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 791 ms / 2,000 ms |
コード長 | 1,159 bytes |
コンパイル時間 | 12,445 ms |
コンパイル使用メモリ | 445,140 KB |
実行使用メモリ | 94,504 KB |
最終ジャッジ日時 | 2024-06-23 01:10:16 |
合計ジャッジ時間 | 18,574 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
import kotlin.system.exitProcess val br = System.`in`.bufferedReader() fun readLine(): String? = br.readLine() fun readStrings() = readLine()?.split(" ")?.filter { it.isNotEmpty() } ?: listOf() fun readInts() = readStrings().map { it.toInt() }.toIntArray() const val MAX_STACK_SIZE: Long = 128 * 1024 * 1024 fun main() { val thread = Thread(null, ::run, "solve", MAX_STACK_SIZE) thread.setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) } thread.start() } fun run() { val (_, M) = readInts() val a = Array(M) { readInts() } output(solve(M, a)) } fun solve(M: Int, a: Array<IntArray>): Boolean { val row = a[0].clone() fun has777(): Boolean { var i = 0 var sum = 0 for (j in row.indices) { sum += row[j] while (i < j && sum > 777) sum -= row[i++] if (sum == 777) return true } return false } if (has777()) return true for (i in 1 until M) { for (j in row.indices) row[j] += a[i][j] if (has777()) return true } return false } fun output(res: Boolean) = println(if (res) "YES" else "NO")