結果

問題 No.334 門松ゲーム
ユーザー むらためむらため
提出日時 2019-01-23 00:04:12
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,262 bytes
コンパイル時間 900 ms
コンパイル使用メモリ 63,720 KB
最終ジャッジ日時 2023-09-14 02:30:17
合計ジャッジ時間 1,368 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 28) Error: cannot open file: queues

ソースコード

diff #

import sequtils,strutils,algorithm,math,sugar,macros,strformat
import sets,tables,intsets,queues,heapqueue,bitops
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord
let n = scan()
let K = newSeqWith(n,scan())
type Win = tuple[a,b,c:int,win:bool]
proc isWin(K:seq[int]):Win =
  if K.len < 3 : return (0,0,0,false)
  var results = newSeq[Win]()
  for a in 0..<K.len:
    for b in (a+1)..<K.len:
      for c in (b+1)..<K.len:
        if K[a] == K[c] : continue
        if not ((K[a] < K[b] and K[b] > K[c]) or
                (K[a] > K[b] and K[b] < K[c])) : continue
        let K2 = K[0..<a] & K[a+1..<b] & K[b+1..<c] & K[c+1..<K.len]
        results &= (a,b,c,not isWin(K2).win)
  if results.len == 0: return (0,0,0,false)
  let wins = results.filterIt(it.win)
  if wins.len == 0 : return (0,0,0,false)
  return wins.sorted(proc(x,y:Win):int =
    if x.a != y.a : return x.a - y.a
    if x.b != y.b : return x.b - y.b
    return x.c - y.c
  )[0]
let win = K.isWin()
if not win.win: echo -1
else: echo win.a," ",win.b," ",win.c
0