結果
問題 |
No.254 文字列の構成
|
ユーザー |
![]() |
提出日時 | 2020-12-23 12:05:27 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 173 ms / 5,000 ms |
コード長 | 844 bytes |
コンパイル時間 | 2,075 ms |
コンパイル使用メモリ | 83,860 KB |
実行使用メモリ | 43,632 KB |
最終ジャッジ日時 | 2024-09-21 16:22:04 |
合計ジャッジ時間 | 8,234 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] counts = new int[40000]; counts[1] = 1; for (int i = 2; i < 40000; i++) { counts[i] = counts[i - 1] + 2 + i - 1 + i - 2; } StringBuilder sb = new StringBuilder(); int idx = 0; for (int i = 39999; i >= 1; i--) { while (n >= counts[i]) { n -= counts[i]; String tmp = (char)(idx % 26 + 'a') + "" + (char)((idx + 1) % 26 + 'a'); for (int j = 1; j < i; j++) { sb.append(tmp); } sb.append((char)(idx % 26 + 'a')); idx += 2; } } System.out.println(sb); } }