結果
| 問題 | 
                            No.1927 AB-CD
                             | 
                    
| コンテスト | |
| ユーザー | 
                             norioc
                         | 
                    
| 提出日時 | 2024-11-22 03:33:42 | 
| 言語 | Elixir  (1.18.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,304 ms / 2,000 ms | 
| コード長 | 855 bytes | 
| コンパイル時間 | 4,651 ms | 
| コンパイル使用メモリ | 61,764 KB | 
| 実行使用メモリ | 156,920 KB | 
| 最終ジャッジ日時 | 2024-11-22 03:34:20 | 
| 合計ジャッジ時間 | 32,256 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
defmodule Main do
  @spec input() :: binary()
  def input, do: IO.read(:line) |> String.trim
  def ii, do: input() |> String.to_integer
  def li, do: input() |> String.split |> Enum.map(&String.to_integer/1)
  def yn(b), do: IO.puts (if b, do: "Yes", else: "No")
  def pow(x, n, mod) do
    cond do
      n == 0 -> 1
      rem(n, 2) == 0 ->
        y = pow(x, div(n, 2), mod)
        rem(y * y, mod)
      true ->
        rem(x * pow(x, n - 1, mod), mod)
    end
  end
  @mod 998244353
  def inv(x) do
    pow(x, @mod-2, @mod)
  end
  def comb(n, k) do
    for i <- 1..k//1, reduce: 1 do
      acc ->
        x = rem(acc * inv(i), @mod)
        rem(x * (n-i+1), @mod)
    end
  end
  def main do
    n = ii()
    cs = input() |> String.graphemes()
    ab = cs |> Enum.count(&(&1 == "A" || &1 == "B"))
    ans = comb(n, ab)
    IO.puts ans
  end
end
            
            
            
        
            
norioc