結果

問題 No.334 門松ゲーム
ユーザー n_knuun_knuu
提出日時 2016-04-02 16:00:51
言語 Nim
(2.0.2)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 3,069 ms
コンパイル使用メモリ 68,148 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 00:13:41
合計ジャッジ時間 4,114 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0