結果

問題 No.254 文字列の構成
ユーザー simansiman
提出日時 2022-03-10 01:41:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 482 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 11,572 KB
実行使用メモリ 15,400 KB
最終ジャッジ日時 2023-10-12 03:07:50
合計ジャッジ時間 5,274 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,124 KB
testcase_01 AC 83 ms
15,276 KB
testcase_02 AC 83 ms
15,128 KB
testcase_03 AC 83 ms
15,128 KB
testcase_04 AC 83 ms
15,152 KB
testcase_05 AC 83 ms
15,036 KB
testcase_06 AC 84 ms
15,116 KB
testcase_07 AC 85 ms
15,212 KB
testcase_08 AC 83 ms
15,240 KB
testcase_09 AC 83 ms
15,324 KB
testcase_10 AC 83 ms
15,076 KB
testcase_11 AC 83 ms
15,124 KB
testcase_12 AC 84 ms
15,260 KB
testcase_13 AC 83 ms
15,084 KB
testcase_14 AC 84 ms
15,084 KB
testcase_15 AC 86 ms
15,308 KB
testcase_16 AC 88 ms
15,276 KB
testcase_17 AC 97 ms
15,192 KB
testcase_18 AC 96 ms
15,224 KB
testcase_19 AC 95 ms
15,356 KB
testcase_20 AC 93 ms
15,400 KB
testcase_21 AC 94 ms
15,368 KB
testcase_22 AC 90 ms
15,288 KB
testcase_23 AC 91 ms
15,288 KB
testcase_24 AC 92 ms
15,240 KB
testcase_25 AC 95 ms
15,368 KB
testcase_26 AC 94 ms
15,192 KB
testcase_27 AC 94 ms
15,264 KB
testcase_28 AC 92 ms
15,260 KB
testcase_29 AC 97 ms
15,188 KB
testcase_30 AC 96 ms
15,292 KB
testcase_31 AC 90 ms
15,328 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0