結果

問題 No.1053 ゲーミング棒
ユーザー ikdikd
提出日時 2020-05-15 23:18:53
言語 F#
(F# 4.0)
結果
AC  
実行時間 895 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 7,096 ms
コンパイル使用メモリ 190,852 KB
実行使用メモリ 74,968 KB
最終ジャッジ日時 2023-10-19 17:08:44
合計ジャッジ時間 22,187 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 366 ms
36,148 KB
testcase_01 AC 84 ms
32,708 KB
testcase_02 AC 363 ms
36,204 KB
testcase_03 AC 365 ms
36,192 KB
testcase_04 AC 364 ms
36,192 KB
testcase_05 AC 85 ms
32,708 KB
testcase_06 AC 87 ms
32,708 KB
testcase_07 AC 88 ms
32,704 KB
testcase_08 AC 366 ms
36,148 KB
testcase_09 AC 87 ms
32,708 KB
testcase_10 AC 86 ms
32,716 KB
testcase_11 AC 374 ms
36,204 KB
testcase_12 AC 365 ms
36,148 KB
testcase_13 AC 87 ms
32,708 KB
testcase_14 AC 85 ms
32,708 KB
testcase_15 AC 361 ms
36,148 KB
testcase_16 AC 85 ms
32,708 KB
testcase_17 AC 364 ms
36,148 KB
testcase_18 AC 359 ms
36,132 KB
testcase_19 AC 84 ms
32,708 KB
testcase_20 AC 85 ms
32,708 KB
testcase_21 AC 85 ms
32,708 KB
testcase_22 AC 361 ms
36,152 KB
testcase_23 AC 412 ms
66,896 KB
testcase_24 AC 389 ms
66,988 KB
testcase_25 AC 888 ms
74,664 KB
testcase_26 AC 895 ms
74,968 KB
testcase_27 AC 84 ms
32,704 KB
testcase_28 AC 84 ms
32,720 KB
testcase_29 AC 83 ms
32,704 KB
testcase_30 AC 107 ms
41,576 KB
testcase_31 AC 391 ms
48,988 KB
testcase_32 AC 392 ms
49,008 KB
testcase_33 AC 392 ms
48,988 KB
testcase_34 AC 394 ms
48,988 KB
testcase_35 AC 394 ms
50,100 KB
testcase_36 AC 392 ms
50,164 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (313 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

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

open System

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)

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

    let a =
        stdin.ReadLine().Split()
        |> Array.map (fun x -> int (x) - 1)
        |> Array.toList
    
    if (ok a (new Set<int>([]))) then
        printfn "0"
        exit 0

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

    printfn "%d" (if (ok b (new Set<int>([]))) then 1 else -1)
    0 // return an integer exit code
0