結果
問題 | No.22 括弧の対応 |
ユーザー | regerege |
提出日時 | 2015-12-05 16:47:38 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 289 ms / 5,000 ms |
コード長 | 1,711 bytes |
コンパイル時間 | 3,955 ms |
コンパイル使用メモリ | 166,520 KB |
実行使用メモリ | 43,804 KB |
最終ジャッジ日時 | 2023-09-27 12:59:08 |
合計ジャッジ時間 | 7,799 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 88 ms
23,352 KB |
testcase_01 | AC | 97 ms
23,300 KB |
testcase_02 | AC | 94 ms
23,356 KB |
testcase_03 | AC | 289 ms
43,804 KB |
testcase_04 | AC | 115 ms
31,764 KB |
testcase_05 | AC | 207 ms
34,948 KB |
testcase_06 | AC | 97 ms
27,528 KB |
testcase_07 | AC | 98 ms
25,400 KB |
testcase_08 | AC | 102 ms
25,520 KB |
testcase_09 | AC | 101 ms
25,396 KB |
testcase_10 | AC | 237 ms
39,200 KB |
testcase_11 | AC | 175 ms
29,964 KB |
testcase_12 | AC | 99 ms
25,420 KB |
testcase_13 | AC | 109 ms
25,404 KB |
testcase_14 | AC | 109 ms
29,592 KB |
testcase_15 | AC | 100 ms
23,476 KB |
testcase_16 | AC | 101 ms
27,448 KB |
testcase_17 | AC | 92 ms
23,424 KB |
testcase_18 | AC | 92 ms
25,364 KB |
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0 Copyright (c) Microsoft Corporation. All Rights Reserved.
ソースコード
open System.Collections let s (a:BitArray) = seq [ for i in 0..(a.Length-1) -> a.Get i ] let inline (@>>) (a:BitArray) n = Seq.append (seq[for i in 1..n -> false]) (s a) |> Seq.take a.Length |> Seq.toArray |> BitArray let inline (@<<) (a:BitArray) n = Seq.append (s a |> Seq.skip n) (seq[for i in 1..n -> false]) |> Seq.take a.Length |> Seq.toArray |> BitArray let inline (@=) (a:BitArray) (b:BitArray) = if a.Length = b.Length then Seq.zip (s a) (s b) |> Seq.forall (fun (a:bool,b:bool) -> a = b) else false let inline (@&) (a:BitArray) (b:BitArray) = let c = new BitArray(a) in c.And(b) let inline (@|) (a:BitArray) (b:BitArray) = let c = new BitArray(a) in c.Or(b) let inline (@^) (a:BitArray) (b:BitArray) = let c = new BitArray(a) in c.Xor(b) let inline (@!) (a:BitArray) = let c = new BitArray(a) in c.Not() let ``No.22 括弧の対応`` () = let (N,K) = let t = stdin.ReadLine().Split(' ') in int t.[0],int t.[1] let cnt (a:BitArray) = a |> Seq.cast |> Seq.map (fun b -> if b then 1 else 0) |> Seq.sum let trace s (b:BitArray) = b |> Seq.cast |> Seq.map (fun b -> if b then "1" else "0") |> Seq.reduce(+) |> printfn "%s: %s" s let mask = BitArray([| for _ in 1..N -> true |]) let T = BitArray([| for i in 1..N -> i = K |]) let A = stdin.ReadLine() |> Seq.map ((=)'(') |> Seq.toArray |> BitArray let B = (@!) A let rec f n a b = let c,d = (a @>> n) @& b, (b @<< n) @& a if cnt a = 0 && cnt b = 0 then failwith "syntax error" elif (c @& T) @= T then K - n elif (d @& T) @= T then K + n else f (n+2) (a @^ d) (b @^ c) f 1 A B |> printfn "%d" ``No.22 括弧の対応`` ()