結果
| 問題 |
No.1053 ゲーミング棒
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2020-05-16 00:04:13 |
| 言語 | F# (F# 4.0) |
| 結果 |
AC
|
| 実行時間 | 490 ms / 2,000 ms |
| コード長 | 966 bytes |
| コンパイル時間 | 8,282 ms |
| コンパイル使用メモリ | 197,356 KB |
| 実行使用メモリ | 77,564 KB |
| 最終ジャッジ日時 | 2024-09-19 14:48:06 |
| 合計ジャッジ時間 | 10,891 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (266 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
// Learn more about F# at http://fsharp.org
open System
let rec ok (a: List<int>) (seen: Set<int>) =
match a |> List.tryHead with
| None -> true
| Some(x) ->
if seen.Contains x
then false
else ok (a |> 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
match freq |> Array.tryFindIndex (fun v -> v >= 2) with
| None -> printfn "0"
| Some(x) ->
let b =
(a |> List.skipWhile (fun y -> y = x))
@ (a |> List.takeWhile (fun y -> y = x))
if (ok b (new Set<int>([]))) then printfn "1" else printfn "-1"
0 // return an integer exit code
ikd