結果
| 問題 | No.1943 消えたAGCT(1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-07-11 01:39:46 | 
| 言語 | OCaml (5.2.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 19 ms / 2,000 ms | 
| コード長 | 936 bytes | 
| コンパイル時間 | 1,477 ms | 
| コンパイル使用メモリ | 21,580 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-11 16:48:16 | 
| 合計ジャッジ時間 | 2,522 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
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
)
            
            
            
        