結果

問題 No.1053 ゲーミング棒
コンテスト
ユーザー ikd
提出日時 2020-05-15 23:10:50
言語 F#
(F# 10.0)
コンパイル:
fsharp_c _filename_
実行:
/usr/bin/dotnet_wrap
結果
WA  
実行時間 -
コード長 952 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,381 ms
コンパイル使用メモリ 216,348 KB
実行使用メモリ 86,100 KB
最終ジャッジ日時 2026-04-08 00:14:26
合計ジャッジ時間 16,903 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (446 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

// Learn more about F# at http://fsharp.org

open System

[<EntryPoint>]
let main argv =
    let n = stdin.ReadLine() |> int

    let a =
        stdin.ReadLine().Split()
        |> Array.map (fun x -> int (x) - 1)
        |> Array.toList

    let mutable freq = Array.create n 0
    for x in a do
        freq.[x] <- freq.[x] + 1
    if freq |> Array.forall (fun v -> v <= 1) then
        printfn "0"
        exit 0
    let x = freq |> Array.findIndex (fun v -> v >= 2)
    let b =
        List.append (a |> List.skipWhile (fun y -> y = x))
            (a |> List.takeWhile (fun y -> y = x))

    let rec ok (c: List<int>) (seen: Set<int>) =
        if c.IsEmpty then
            true
        else
            let x = c.Head
            if seen.Contains x
            then false
            else ok (c |> List.skipWhile (fun y -> y = x)) (seen.Add x)
    printfn "%d" (if (ok b (new Set<int>([]))) then 1 else -1)
    0 // return an integer exit code
0