結果
問題 |
No.3001 ヘビ文字列
|
ユーザー |
![]() |
提出日時 | 2025-01-01 12:40:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 644 ms / 1,500 ms |
コード長 | 3,115 bytes |
コンパイル時間 | 2,870 ms |
コンパイル使用メモリ | 202,224 KB |
実行使用メモリ | 144,408 KB |
最終ジャッジ日時 | 2025-01-01 12:40:45 |
合計ジャッジ時間 | 37,346 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 83 |
ソースコード
#include <algorithm> #include <array> #include <bit> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <concepts> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numbers> #include <numeric> #include <queue> #include <random> #include <ranges> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> constexpr int MOD{1'000'000'007}; constexpr int MOD2{998'244'353}; constexpr int INF{1'000'000'000}; //1e9 constexpr int NIL{-1}; constexpr long long LINF{1'000'000'000'000'000'000}; // 1e18 constexpr long double EPS{1E-10L}; using namespace std::literals; namespace ranges = std::ranges; namespace views = ranges::views; template<class T, class S> bool chmax(T &a, const S &b){ if(a < b){a = b; return true;} return false; } template<class T, class S> bool chmin(T &a, const S &b){ if(b < a){a = b; return true;} return false; } template<class T> bool inside(T x, T lx, T rx){ //semi-open return (ranges::clamp(x, lx, rx-1) == x); } template<class T> bool inside(T x, T y, T lx, T rx, T ly, T ry){ return inside(x, lx, rx) && inside(y, ly, ry); } template<class T, class S> std::istream &operator>>(std::istream &is, std::pair<T, S> &p){ return is >> p.first >> p.second; } template<class T, class S> std::ostream &operator<<(std::ostream &os, const std::pair<T, S> &p){ return os << p.first << " " << p.second; } template<class T> std::istream &operator>>(std::istream &is, std::vector<T> &v){ {for(auto &e: v) is >> e;} return is; } template<class Container> void print_container(const Container &c, std::string sep = " "s, std::string end = "\n"s){ for(int i{int(std::size(c))}; auto e: c) std::cout << e << (--i ? sep : end); } std::string yesno(bool x){return x ? "Yes"s : "No"s;} std::vector<long long> primeFactor(long long n){ std::vector<long long> vec; for(long long i{2}; i * i <= n; ++i) if(!(n % i)){ vec.push_back(i); while(!(n % i)) n /= i; } if(n > 1) vec.push_back(n); return vec; } int main(){ std::string S; std::cin >> S; int N{int(std::size(S))}; auto primes{primeFactor(N)}; int op_num{INF}; auto ans{S}; for(auto p: primes){ int a{int(N / p)}, op{}; std::string s; std::vector cnts(a, std::vector<int>(26, 0)); for(int i{}; i < N; ++i) ++cnts[i % a][S[i] - 'A']; for(int i{}; i < a; ++i){ auto max_it{ranges::max_element(cnts[i])}; op += p - *max_it; s += char('A' + int(std::distance(std::begin(cnts[i]), max_it))); } if(chmin(op_num, op)){ ans = s; for(int i{1}; i < p; ++i) ans += s; } } std::cout << ans << std::endl; return 0; }