結果
| 問題 | No.254 文字列の構成 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-16 14:17:00 |
| 言語 | D (dmd 2.112.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,022 bytes |
| 記録 | |
| コンパイル時間 | 3,733 ms |
| コンパイル使用メモリ | 172,844 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-16 14:17:06 |
| 合計ジャッジ時間 | 5,676 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
module main;
// https://drken1215.hatenablog.com/entry/2024/04/26/232753 より
// 文字列処理、貪欲法
import std;
// 整数平方根
T isqrt(T)(T x)
{
assert(x >= 0);
if (x <= 1) return x;
T s = 1, x1 = x - 1;
static if (T.sizeof >= 8)
if (x1 > 4_294_967_295L) { s += 16; x1 >>= 32; }
static if (T.sizeof >= 4)
if (x1 > 65_535) { s += 8; x1 >>= 16; }
static if (T.sizeof >= 2)
if (x1 > 255) { s += 4; x1 >>= 8; }
if (x1 > 15) { s += 2; x1 >>= 4; }
if (x1 > 3) ++s;
T g0 = T(1) << s, g1 = (g0 + (x >> s)) >> 1;
// 近似値が厳密に減少する間行う
while (g1 < g0) {
g0 = g1;
g1 = (g0 + x / g0) >> 1;
}
return g0;
}
// a -> 1
// aba -> 4
// ababa -> 9
// abababa -> 16
void main()
{
// 入力
long N = readln.chomp.to!long;
// 答えの計算
string ans;
char letter = 'a';
while (N > 0) {
long sq = isqrt(N);
ans ~= letter;
foreach (_; 0 .. sq - 1) {
ans ~= letter + 1;
ans ~= letter;
}
N -= sq * sq;
letter += 2;
}
// 答えの出力
writeln(ans);
}