結果

問題 No.607 開通777年記念
ユーザー qszhuqszhu
提出日時 2022-10-08 22:54:20
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,926 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 20,497 ms
コンパイル使用メモリ 430,872 KB
実行使用メモリ 64,636 KB
最終ジャッジ日時 2023-09-05 04:05:57
合計ジャッジ時間 27,093 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 298 ms
55,380 KB
testcase_01 AC 295 ms
53,228 KB
testcase_02 AC 298 ms
55,024 KB
testcase_03 AC 295 ms
53,220 KB
testcase_04 AC 298 ms
53,280 KB
testcase_05 AC 296 ms
55,028 KB
testcase_06 AC 296 ms
55,376 KB
testcase_07 AC 664 ms
57,892 KB
testcase_08 AC 299 ms
53,380 KB
testcase_09 AC 385 ms
55,648 KB
testcase_10 AC 373 ms
57,280 KB
testcase_11 AC 1,807 ms
64,636 KB
testcase_12 AC 1,926 ms
64,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
 */
0