結果

問題 No.22 括弧の対応
ユーザー regeregeregerege
提出日時 2015-12-05 16:47:38
言語 F#
(F# 4.0)
結果
AC  
実行時間 324 ms / 5,000 ms
コード長 1,711 bytes
コンパイル時間 4,785 ms
コンパイル使用メモリ 164,828 KB
実行使用メモリ 43,808 KB
最終ジャッジ日時 2023-09-27 12:59:00
合計ジャッジ時間 8,217 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
23,492 KB
testcase_01 AC 103 ms
23,516 KB
testcase_02 AC 103 ms
23,428 KB
testcase_03 AC 324 ms
43,808 KB
testcase_04 AC 124 ms
28,008 KB
testcase_05 AC 237 ms
34,932 KB
testcase_06 AC 111 ms
27,580 KB
testcase_07 AC 110 ms
27,520 KB
testcase_08 AC 111 ms
25,400 KB
testcase_09 AC 111 ms
25,384 KB
testcase_10 AC 255 ms
37,252 KB
testcase_11 AC 194 ms
29,912 KB
testcase_12 AC 108 ms
25,488 KB
testcase_13 AC 111 ms
25,480 KB
testcase_14 AC 113 ms
29,624 KB
testcase_15 AC 112 ms
25,560 KB
testcase_16 AC 114 ms
25,372 KB
testcase_17 AC 104 ms
23,420 KB
testcase_18 AC 102 ms
25,524 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

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 括弧の対応`` ()
0