結果
| 問題 |
No.3001 ヘビ文字列
|
| ユーザー |
addeight2
|
| 提出日時 | 2024-12-22 15:26:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,165 bytes |
| コンパイル時間 | 2,277 ms |
| コンパイル使用メモリ | 180,356 KB |
| 実行使用メモリ | 25,800 KB |
| 最終ジャッジ日時 | 2025-01-01 07:34:57 |
| 合計ジャッジ時間 | 86,347 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 63 TLE * 20 |
ソースコード
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, a) FOR(i, 0, a)
using namespace std;
using ll = long long;
pair<ll, string> solve_w_period(string S, ll period) {
ll n = S.length(), ans = 0;
vector<ll> char_cnt_vec;
bool flg = (n / period * 2 < 13);
if (!flg) {
char_cnt_vec.resize('Z' - 'A' + 1);
}
REP(i, period) {
map<char, ll> char_cnt;
pair<char, ll> max_cnt;
if (flg) {
REP(j, n / period) {
++char_cnt[S[i + period * j]];
}
max_cnt = *max_element(char_cnt.begin(), char_cnt.end(),
[](auto a, auto b) { return a.second < b.second; });
}else{
REP(j, n / period) {
++char_cnt_vec[S[i + period * j] - 'A'];
}
ll max_ele = max_element(char_cnt_vec.begin(), char_cnt_vec.end())
- char_cnt_vec.begin();
max_cnt.first = 'A' + max_ele;
max_cnt.second = char_cnt_vec[max_ele];
if (n / period < 26){
REP(j, n / period) char_cnt_vec[S[i + period * j] - 'A'] = 0;
}else{
fill(char_cnt_vec.begin(), char_cnt_vec.end(), 0);
}
}
ans += n / period - max_cnt.second;
REP(j, n / period) {
S[i + period * j] = max_cnt.first;
}
}
return make_pair(ans, S);
}
string solve(const string &S) {
ll n = S.length();
auto ans = make_pair(n, S);
for (ll period = 1; period * period <= n; ++period) {
if (n % period == 0) {
auto temp_ans = solve_w_period(S, period);
if (temp_ans.first < ans.first) {
ans = temp_ans;
}
if (period != 1) {
temp_ans = solve_w_period(S, n / period);
if (temp_ans.first < ans.first) {
ans = temp_ans;
}
}
}
}
return ans.second;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string S;
cin >> S;
cout << solve(S) << endl;
}
addeight2