結果
| 問題 |
No.607 開通777年記念
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-08 22:54:20 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 1,953 ms / 2,000 ms |
| コード長 | 1,314 bytes |
| コンパイル時間 | 16,280 ms |
| コンパイル使用メモリ | 457,908 KB |
| 実行使用メモリ | 91,044 KB |
| 最終ジャッジ日時 | 2024-06-23 00:45:59 |
| 合計ジャッジ時間 | 25,588 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 (N, M) = readInts()
val a = Array(M) { readInts() }
output(solve(N, M, a))
}
fun solve(N: Int, M: Int, a: Array<IntArray>): Boolean {
val preSum = a[0].scan(0, Int::plus).toIntArray()
fun has777(): Boolean {
for (i in 0 until N) {
for (j in 1..N) {
if (preSum[j] - preSum[i] == 777) return true
}
}
return false
}
if (has777()) return true
for (i in 1 until M) {
var s = 0
for (j in 1..N) {
s += a[i][j - 1]
preSum[j] += s
}
if (has777()) return true
}
return false
}
fun output(res: Boolean) = println(if (res) "YES" else "NO")
/*
10 700 0 0 3
10 710 710 710 713
0 0 70 7 -1
10 700 70 7 2
10 710 780 787 789
1 1 1 1 1
11 701 71 8 3
*/