結果
問題 | No.3135 AAABC |
ユーザー |
![]() |
提出日時 | 2025-05-02 21:46:17 |
言語 | Crystal (1.14.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 570 bytes |
コンパイル時間 | 13,604 ms |
コンパイル使用メモリ | 307,860 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-05-02 21:46:32 |
合計ジャッジ時間 | 12,834 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
n = read_line.to_i s = read_line.to_i s -= 1 ans = Array.new(n, -1) n.times do |i| ok = false 3.times do |j| ans[i] = j used = Array.new(3) { |k| ans.includes?(k) } c = count(n - 1 - i, used) if c > s ok = true break else s -= c end end if !ok puts -1 exit end end puts ans.map { |i| 'A' + i }.join def count(len, used) return 0 if used.count(false) > len ret = 3 ** len 3.times do |i| if !used[i] ret -= 2 ** len end if !used[i] && !used[i - 1] ret += 1 end end ret end