結果
問題 |
No.1426 Got a Covered OR
|
ユーザー |
|
提出日時 | 2020-12-01 08:32:47 |
言語 | Kotlin (2.1.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,277 bytes |
コンパイル時間 | 11,121 ms |
コンパイル使用メモリ | 440,976 KB |
実行使用メモリ | 99,216 KB |
最終ジャッジ日時 | 2024-09-19 21:11:11 |
合計ジャッジ時間 | 18,804 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 7 TLE * 1 -- * 16 |
コンパイルメッセージ
Main.kt:9:22: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int val max = 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 } val max = b.max()!! if (max > 10) { println(0) } else { dfs(a, b, 0, 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() }