結果
問題 |
No.3290 Encrypt Failed, but Decrypt Succeeded
|
ユーザー |
![]() |
提出日時 | 2025-08-28 03:07:54 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 905 ms / 2,000 ms |
コード長 | 782 bytes |
コンパイル時間 | 505 ms |
コンパイル使用メモリ | 7,936 KB |
実行使用メモリ | 47,172 KB |
最終ジャッジ日時 | 2025-08-28 03:08:11 |
合計ジャッジ時間 | 16,216 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
コンパイルメッセージ
Syntax OK
ソースコード
map = "abcdefghijklmnopqrstuvwxyz".chars cnt = 1 hash = {} map.each do |v| hash[v] = cnt hash[cnt] = v cnt += 1 end n,k = gets.split.map(&:to_i) s = gets.chomp.chars.map{|v|v.to_i} # 数え上げ dp = Array.new(n+1, 0) dp[n] = 1 (n-1).downto(0) do |i| # 先頭が 0 を除く if s[i] != 0 # 一桁使う dp[i] += dp[i+1] # 二桁使う if i != n-1 x = s[i..i+1].join.to_i if hash[x] != nil dp[i] += dp[i+2] end end dp[i] = 10**18 if dp[i] > 10**18 end end # 復元 ans = [] i = 0 rest = k while i < n if dp[i+1] >= rest ans << hash[s[i]] i += 1 next end rest -= dp[i+1] if i+1 < n x = s[i..i+1].join.to_i if hash[x] != nil ans << hash[x] i += 2 end end end puts ans.join