結果
| 問題 |
No.1426 Got a Covered OR
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-29 17:19:54 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,193 bytes |
| コンパイル時間 | 11,721 ms |
| コンパイル使用メモリ | 448,676 KB |
| 実行使用メモリ | 104,856 KB |
| 最終ジャッジ日時 | 2024-09-19 21:10:30 |
| 合計ジャッジ時間 | 16,180 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 TLE * 1 |
| other | -- * 24 |
コンパイルメッセージ
Main.kt:9:25: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int
dfs(a, b, 0, b.max()!!)
^
ソースコード
import java.io.InputStream
import java.io.PrintWriter
import java.util.*
fun PrintWriter.solve() = with(FastScanner(System.`in`)) {
val n = nextInt()
val b = Array(n) { nextInt() }
val a = Array(n) { 0 }
dfs(a, b, 0, b.max()!!)
println(count)
}
var count = 0L
fun dfs(a: Array<Int>, b: Array<Int>, i: Int, max: Int) {
val n = a.count()
if (i == n) {
val a_or = Array(n) { a[0] }
for (j in 1 until n) {
a_or[j] = a_or[j - 1] or a[j]
}
if ((0 until n).all { b[it] == -1 || b[it] == a_or[it] }) count++
} else {
for (v in 1..max) {
a[i] = v
dfs(a, b, i + 1, max)
}
}
}
fun main() {
val writer = PrintWriter(System.out, false)
writer.solve()
writer.flush()
}
class FastScanner(s: InputStream) {
private var st = StringTokenizer("")
private val br = s.bufferedReader()
fun next(): String {
while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
return st.nextToken()
}
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
}