結果
問題 | No.999 てん vs. ほむ |
ユーザー | mikhail |
提出日時 | 2020-03-23 21:22:16 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 715 ms / 2,000 ms |
コード長 | 2,994 bytes |
コンパイル時間 | 17,321 ms |
コンパイル使用メモリ | 464,720 KB |
実行使用メモリ | 90,772 KB |
最終ジャッジ日時 | 2024-06-08 15:07:17 |
合計ジャッジ時間 | 30,659 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 318 ms
55,392 KB |
testcase_01 | AC | 340 ms
55,372 KB |
testcase_02 | AC | 323 ms
55,596 KB |
testcase_03 | AC | 324 ms
55,588 KB |
testcase_04 | AC | 339 ms
55,640 KB |
testcase_05 | AC | 332 ms
55,704 KB |
testcase_06 | AC | 321 ms
55,708 KB |
testcase_07 | AC | 327 ms
55,660 KB |
testcase_08 | AC | 426 ms
57,296 KB |
testcase_09 | AC | 693 ms
86,004 KB |
testcase_10 | AC | 548 ms
70,536 KB |
testcase_11 | AC | 536 ms
66,536 KB |
testcase_12 | AC | 570 ms
77,104 KB |
testcase_13 | AC | 708 ms
90,388 KB |
testcase_14 | AC | 707 ms
90,348 KB |
testcase_15 | AC | 693 ms
90,196 KB |
testcase_16 | AC | 715 ms
90,328 KB |
testcase_17 | AC | 656 ms
86,672 KB |
testcase_18 | AC | 657 ms
86,860 KB |
testcase_19 | AC | 661 ms
86,712 KB |
testcase_20 | AC | 666 ms
86,972 KB |
testcase_21 | AC | 679 ms
89,644 KB |
testcase_22 | AC | 679 ms
90,772 KB |
コンパイルメッセージ
Main.kt:9:10: warning: parameter 'args' is never used fun main(args: Array<String>){ ^ Main.kt:67:118: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int fun max(a: Int = -INF, b: Int = -INF, c: Int = -INF, d: Int = -INF, e: Int = -INF): Int = listOf(a, b, c, d, e).max()!! ^ Main.kt:68:129: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Long fun max(a: Long = -LINF, b: Long = -LINF, c: Long = -LINF, d: Long = -LINF, e: Long = -LINF): Long = listOf(a, b, c, d, e).max()!!.toLong() ^ Main.kt:69:113: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int fun min(a: Int = INF, b: Int = INF, c: Int = INF, d: Int = INF, e: Int = INF): Int = listOf(a, b, c, d, e).min()!! ^ Main.kt:70:124: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Long fun min(a: Long = LINF, b: Long = LINF, c: Long = LINF, d: Long = LINF, e: Long = LINF): Long = listOf(a, b, c, d, e).min()!!.toLong() ^
ソースコード
import java.util.* import java.io.* val pw = PrintWriter(System.out) val MOD = 1000000007L val INF = 2147483647 val LINF = 9223372036854775807L fun main(args: Array<String>){ solve() pw.flush() } fun solve(){ val n = nextInt() val a = nextLongList() val b = LongArray(n) { 0L } val c = LongArray(n) { 0L } for (i in 0 until 2 * n step 2) { b[i / 2] = a[i] - a[i + 1] } for (i in 2 * n - 2 downTo 0 step 2) { c[i / 2] = a[i + 1] - a[i] } val s = LongArray(n + 1) { 0 } val t = LongArray(n + 1) { 0 } for (i in b.indices) { s[i + 1] = s[i] + b[i] } for (i in n - 1 downTo 0) { t[i] = t[i + 1] + c[i] } var ans = 0L for (i in 0..n) { ans = max(ans, s[i] + t[i]) } println(ans) } // Print fun println(v: String){ pw.println(v) } fun print(v: String){ pw.print(v) } // Read fun next() = readLine()!! fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextDouble() = next().toDouble() fun nextList() = next().split(" ") fun nextIntList() = next().split(" ").map{ it.toInt() } fun nextLongList() = next().split(" ").map{ it.toLong() } fun nextDoubleList() = next().split(" ").map{ it.toDouble() } fun nextAryln(n: Int) = Array(n){ next() } fun nextIntAryln(n: Int) = IntArray(n){ nextInt() } fun nextLongAryln(n: Int) = LongArray(n){ nextLong() } fun nextDoubleAryln(n: Int) = DoubleArray(n) { nextDouble() } // Math fun abs(n: Int) : Int = Math.abs(n) fun abs(n: Long) : Long = Math.abs(n) fun abs(n: Double) : Double = Math.abs(n) fun max(a: Int = -INF, b: Int = -INF, c: Int = -INF, d: Int = -INF, e: Int = -INF): Int = listOf(a, b, c, d, e).max()!! fun max(a: Long = -LINF, b: Long = -LINF, c: Long = -LINF, d: Long = -LINF, e: Long = -LINF): Long = listOf(a, b, c, d, e).max()!!.toLong() fun min(a: Int = INF, b: Int = INF, c: Int = INF, d: Int = INF, e: Int = INF): Int = listOf(a, b, c, d, e).min()!! fun min(a: Long = LINF, b: Long = LINF, c: Long = LINF, d: Long = LINF, e: Long = LINF): Long = listOf(a, b, c, d, e).min()!!.toLong() fun prime(from: Long, to: Long = from) : List<Long>{ return (from..to).filter{ i -> val max = Math.sqrt(i.toDouble()).toLong() (2..max).all{ j -> i % j != 0L} } } fun gcd(a: Long, b: Long) : Long = if(a % b == 0L) b else gcd(b, (a % b)) fun lcm(a: Long, b: Long) : Long = a / gcd(a, b) * b fun modpow(a: Long, n: Long, p:Long = MOD) : Long { var res = 1L var ar = a var nr = n while(nr > 0){ if((nr and 1) == 1L) res = res * ar % p ar = ar * ar % p nr = nr shr 1 } return res } fun modinv(a: Long, p: Long = MOD) : Long = modpow(a, p - 2, p) fun ncr(n: Long, r: Long) : Long { var a = 1L var b = 1L for (i in 1..r) { a = a * (n + 1 - i) % MOD b = b * i % MOD } return modinv(b, MOD) * a % MOD }