結果

問題 No.171 スワップ文字列(Med)
ユーザー yuruhiya
提出日時 2020-05-10 10:29:09
言語 Crystal
(1.14.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 451 bytes
コンパイル時間 12,350 ms
コンパイル使用メモリ 295,012 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-06-30 20:08:27
合計ジャッジ時間 12,720 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 573

def calc_combination(n)
  res = Array.new(n + 1) { Array.new(n + 1, 1) }
  2.upto(n) do |i|
    1.upto(i - 1) do |j|
      res[i][j] = res[i-1][j-1] + res[i-1][j] % MOD
      res[j][i] = res[i][j]
    end
  end
  res
end

s = read_line
comb = calc_combination(s.size)
cnt = Array.new(26, 0)
s.each_char do |c|
  cnt[c - 'A'] += 1
end

m = s.size
ans = 1
cnt.each do |i|
  ans = ans * comb[m][i] % MOD
  m -= i
end
puts (ans + MOD - 1) % MOD
0