結果
| 問題 |
No.254 文字列の構成
|
| ユーザー |
drken1215
|
| 提出日時 | 2024-04-26 22:37:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 751 bytes |
| コンパイル時間 | 2,118 ms |
| コンパイル使用メモリ | 192,712 KB |
| 最終ジャッジ日時 | 2025-02-21 09:11:23 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
// b の数を x とすると、(x + 2) * (x + 3) / 2 - 2
// a -> 1
// aba -> 4
// ababa -> 8
// abababa -> 13
const long long MAX = 100000;
int main() {
string res = "";
char letter = 'a';
long long N;
cin >> N;
while (N > 0) {
long long low = -1, high = MAX;
while (high - low > 1) {
long long x = (low + high) / 2;
if ((x + 2) * (x + 3) / 2 - 2 <= N) low = x;
else high = x;
}
res += letter;
for (int i = 0; i < low; ++i) {
res += (char)(letter + 1);
res += letter;
}
N -= (low + 2) * (low + 3) / 2 - 2;
letter += 2;
}
cout << res << endl;
}
drken1215