結果

問題 No.1943 消えたAGCT(1)
ユーザー xsdxsd
提出日時 2022-07-11 01:39:46
言語 OCaml
(5.1.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 936 bytes
コンパイル時間 3,240 ms
コンパイル使用メモリ 20,084 KB
実行使用メモリ 5,000 KB
最終ジャッジ日時 2023-09-02 10:06:55
合計ジャッジ時間 4,478 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 14 ms
5,000 KB
testcase_10 AC 12 ms
4,792 KB
testcase_11 AC 12 ms
4,904 KB
testcase_12 AC 15 ms
4,892 KB
testcase_13 AC 9 ms
4,492 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 16 ms
4,856 KB
testcase_16 AC 13 ms
4,552 KB
testcase_17 AC 14 ms
4,732 KB
testcase_18 AC 16 ms
4,760 KB
testcase_19 AC 16 ms
4,936 KB
testcase_20 AC 16 ms
4,900 KB
testcase_21 AC 17 ms
4,792 KB
testcase_22 AC 22 ms
4,940 KB
testcase_23 AC 22 ms
4,900 KB
testcase_24 AC 11 ms
4,792 KB
testcase_25 AC 12 ms
4,792 KB
testcase_26 AC 12 ms
4,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

type t = L | R ;;
Scanf.scanf "%d %s" (fun n s ->
    let isagct c = c = 'A' || c = 'G' || c = 'C' || c = 'T' in
    let rec loop i acc =
        if i = n then acc else
            let acc = acc + if isagct s.[i] then 1 else 0 in
            loop (i + 1) acc
    in
    let ct = loop 0 0 in
    let rec sim count rest l r prev =
        if rest = 0 then count else
            match prev with
            | L ->
                if isagct s.[l] then sim (count + 1) (rest - 1) (l - 1) r L
                                else sim (count + 1) rest       (l - 1) r R
            | R ->
                if isagct s.[r] then sim (count + 1) (rest - 1) l (r + 1) L
                                else sim (count + 1) rest       l (r + 1) R
    in
    Printf.printf "%d\n" @@ 
        if ct = 0 then 0 else
            if isagct s.[ct - 1] then sim 1 (ct - 1) (ct - 2) ct L
                                 else sim 1 ct       (ct - 2) ct R
)
0