結果
| 問題 |
No.3001 ヘビ文字列
|
| ユーザー |
hitonanode
|
| 提出日時 | 2025-01-01 09:26:06 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 399 ms / 1,500 ms |
| コード長 | 1,150 bytes |
| コンパイル時間 | 1,349 ms |
| コンパイル使用メモリ | 98,904 KB |
| 実行使用メモリ | 9,204 KB |
| 最終ジャッジ日時 | 2025-01-01 09:26:32 |
| 合計ジャッジ時間 | 25,430 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 83 |
ソースコード
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
string S;
cin >> S;
const int N = S.size();
vector<int> ds{1};
int tmp = N;
for (int d = 2; d <= tmp; ++d) {
if (tmp % d == 0) {
ds.push_back(N / d);
while (tmp % d == 0) tmp /= d;
}
}
if (tmp != 1) ds.push_back(N / tmp);
int ret = N + 1;
auto argmin = S;
for (int d : ds) {
if (d == N) continue;
int cost = 0;
string tmp = S;
for (int h = 0; h < d; ++h) {
vector<int> cntr(26);
for (int i = h; i < N; i += d) cntr[S[i] - 'A']++;
int maxi = max_element(cntr.begin(), cntr.end()) - cntr.begin();
for (int i = h; i < N; i += d) {
if (S[i] - 'A' != maxi) {
tmp[i] = char('A' + maxi);
cost++;
}
}
}
if (cost < ret) {
ret = cost;
argmin = tmp;
}
}
cout << argmin << '\n';
}
hitonanode