結果
問題 | No.334 門松ゲーム |
ユーザー |
![]() |
提出日時 | 2016-04-02 16:00:51 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 912 bytes |
コンパイル時間 | 2,998 ms |
コンパイル使用メモリ | 66,552 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-29 13:27:34 |
合計ジャッジ時間 | 3,622 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
import strutils, sequtils let N = stdin.readline.parseInt K = stdin.readline.split.map(parseInt) var dp = newSeqWith(1 shl N, -1) proc is_kadomatsu(A, B, C: int): bool = return A != B and B != C and C != A and (max(A, C) < B or min(A, C) > B) proc dpdp(state: int): int = if dp[state] != -1: return dp[state] for i in 0..<N: for j in i+1..<N: for k in j+1..<N: if is_kadomatsu(K[i], K[j], K[k]) and ((state shr i) and 1) == 0 and ((state shr j) and 1) == 0 and ((state shr k) and 1) == 0 and dpdp(state or (1 shl i) or (1 shl j) or (1 shl k)) == 0: dp[state] = 1 return 1 dp[state] = 0 return 0 proc main() = if dpdp(0) == 0: echo(-1) return else: for a in 0..<N: for b in a+1..<N: for c in b+1..<N: if dp[(1 shl a) or (1 shl b) or (1 shl c)] == 0: echo(a, ' ', b, ' ', c) return main()