結果
問題 | No.254 文字列の構成 |
ユーザー |
![]() |
提出日時 | 2022-03-10 01:41:44 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 105 ms / 5,000 ms |
コード長 | 482 bytes |
コンパイル時間 | 70 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,544 KB |
最終ジャッジ日時 | 2024-09-14 02:55:24 |
合計ジャッジ時間 | 4,520 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
コンパイルメッセージ
Syntax OK
ソースコード
N = gets.to_i def build_str(ch, len) res = '' (len - 1).times do res << ch res << ch.succ end res << ch ch.succ! if ch == 'z' ch = 'a' else ch.succ! end res end cur = 'a' ans = '' n = N while n > 0 len = 0 cnt = 0 while (cnt * (cnt + 1)) / 2 + (cnt * (cnt - 1)) / 2 <= n cnt += 1 len += 1 end cnt -= 1 len -= 1 n -= (cnt * (cnt + 1)) / 2 + (cnt * (cnt - 1)) / 2 str = build_str(cur, len) ans << str end puts ans