結果
問題 |
No.3001 ヘビ文字列
|
ユーザー |
|
提出日時 | 2025-01-02 01:56:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 339 ms / 1,500 ms |
コード長 | 1,266 bytes |
コンパイル時間 | 5,821 ms |
コンパイル使用メモリ | 348,620 KB |
実行使用メモリ | 110,700 KB |
最終ジャッジ日時 | 2025-01-02 01:56:36 |
合計ジャッジ時間 | 27,379 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 83 |
ソースコード
#include <bits/extc++.h> int main() { using namespace std; string S; cin >> S; const unsigned N(size(S)); string ans{}; auto prefix_min{numeric_limits<unsigned>::max()}; unsigned repeat{}; for (const auto p : [](unsigned N) { vector<unsigned> result; for (unsigned p{2}; p * p <= N; ++p) if (N % p == 0) { result.emplace_back(p); while (N % p == 0) N /= p; } if (N > 1) result.emplace_back(N); return result; }(N) | views::transform([N](const auto p){ return N / p; })) { vector<array<unsigned, 26>> counter(p); for (unsigned i{}; const auto c : S) ++counter[i++ % p][c - 65]; auto modify_count{N}; string tmp{}; for (const auto &x : counter) { const auto &it{ranges::max_element(x)}; tmp += static_cast<char>(ranges::distance(begin(x), it) + 65); modify_count -= *it; } if (modify_count < prefix_min) { prefix_min = modify_count; ans = tmp; repeat = N / p; } } for (unsigned i{}; i < repeat; ++i) cout << ans; cout << endl; return 0; }