結果

問題 No.3001 ヘビ文字列
ユーザー apricityapricity
提出日時 2025-01-01 10:10:09
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 350 ms / 1,500 ms
コード長 12,390 bytes
コンパイル時間 2,385 ms
コンパイル使用メモリ 142,428 KB
実行使用メモリ 23,072 KB
最終ジャッジ日時 2025-01-01 10:10:41
合計ジャッジ時間 27,657 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,816 KB
testcase_02 AC 3 ms
6,820 KB
testcase_03 AC 3 ms
6,816 KB
testcase_04 AC 2 ms
6,820 KB
testcase_05 AC 3 ms
6,816 KB
testcase_06 AC 4 ms
6,820 KB
testcase_07 AC 4 ms
6,820 KB
testcase_08 AC 3 ms
6,816 KB
testcase_09 AC 3 ms
6,816 KB
testcase_10 AC 3 ms
6,820 KB
testcase_11 AC 3 ms
6,816 KB
testcase_12 AC 3 ms
6,820 KB
testcase_13 AC 3 ms
6,820 KB
testcase_14 AC 3 ms
6,816 KB
testcase_15 AC 298 ms
22,988 KB
testcase_16 AC 286 ms
23,024 KB
testcase_17 AC 298 ms
23,048 KB
testcase_18 AC 291 ms
23,060 KB
testcase_19 AC 331 ms
23,036 KB
testcase_20 AC 285 ms
23,012 KB
testcase_21 AC 293 ms
22,972 KB
testcase_22 AC 294 ms
22,872 KB
testcase_23 AC 299 ms
22,872 KB
testcase_24 AC 297 ms
23,000 KB
testcase_25 AC 105 ms
23,068 KB
testcase_26 AC 113 ms
23,012 KB
testcase_27 AC 145 ms
23,008 KB
testcase_28 AC 126 ms
22,992 KB
testcase_29 AC 116 ms
23,052 KB
testcase_30 AC 110 ms
22,972 KB
testcase_31 AC 114 ms
23,072 KB
testcase_32 AC 106 ms
23,044 KB
testcase_33 AC 112 ms
23,048 KB
testcase_34 AC 127 ms
23,008 KB
testcase_35 AC 116 ms
22,916 KB
testcase_36 AC 113 ms
22,836 KB
testcase_37 AC 134 ms
22,744 KB
testcase_38 AC 116 ms
22,832 KB
testcase_39 AC 123 ms
22,772 KB
testcase_40 AC 107 ms
22,736 KB
testcase_41 AC 106 ms
22,840 KB
testcase_42 AC 115 ms
22,916 KB
testcase_43 AC 117 ms
22,744 KB
testcase_44 AC 124 ms
22,920 KB
testcase_45 AC 319 ms
22,628 KB
testcase_46 AC 281 ms
22,736 KB
testcase_47 AC 325 ms
22,704 KB
testcase_48 AC 337 ms
22,624 KB
testcase_49 AC 350 ms
22,492 KB
testcase_50 AC 329 ms
22,552 KB
testcase_51 AC 280 ms
22,640 KB
testcase_52 AC 286 ms
22,648 KB
testcase_53 AC 327 ms
22,724 KB
testcase_54 AC 280 ms
22,668 KB
testcase_55 AC 281 ms
22,900 KB
testcase_56 AC 321 ms
22,952 KB
testcase_57 AC 331 ms
22,976 KB
testcase_58 AC 284 ms
22,968 KB
testcase_59 AC 307 ms
23,028 KB
testcase_60 AC 286 ms
22,912 KB
testcase_61 AC 271 ms
22,812 KB
testcase_62 AC 308 ms
22,836 KB
testcase_63 AC 298 ms
22,972 KB
testcase_64 AC 306 ms
22,944 KB
testcase_65 AC 145 ms
16,452 KB
testcase_66 AC 191 ms
22,580 KB
testcase_67 AC 192 ms
22,748 KB
testcase_68 AC 92 ms
18,380 KB
testcase_69 AC 87 ms
16,636 KB
testcase_70 AC 134 ms
22,372 KB
testcase_71 AC 95 ms
14,924 KB
testcase_72 AC 107 ms
16,704 KB
testcase_73 AC 90 ms
14,148 KB
testcase_74 AC 145 ms
20,120 KB
testcase_75 AC 272 ms
22,988 KB
testcase_76 AC 316 ms
22,940 KB
testcase_77 AC 278 ms
22,824 KB
testcase_78 AC 326 ms
22,984 KB
testcase_79 AC 261 ms
22,932 KB
testcase_80 AC 264 ms
22,952 KB
testcase_81 AC 329 ms
22,984 KB
testcase_82 AC 266 ms
22,940 KB
testcase_83 AC 278 ms
22,884 KB
testcase_84 AC 288 ms
22,988 KB
testcase_85 AC 3 ms
6,816 KB
testcase_86 AC 2 ms
6,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<utility>
#include<tuple>
#include<array>
#include<cstdint>
#include<cstdio>
#include<iomanip>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<cctype>
#include<chrono>
#include<random>
#include<cassert>
#include<cstddef>
#include<iterator>
#include<string_view>
#include<type_traits>
#include<functional>

#ifdef LOCAL
#  include "debug_print.hpp"
#  define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define debug(...) (static_cast<void>(0))
#endif

using namespace std;

namespace io {

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
    is >> p.first >> p.second;
    return is;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (auto &x : v) is >> x;
    return is;
}
template <typename T, size_t N = 0>
istream &operator>>(istream &is, array<T, N> &v) {
    for (auto &x : v) is >> x;
    return is;
}
template <size_t N = 0, typename T>
istream& cin_tuple_impl(istream &is, T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        is >> x;
        cin_tuple_impl<N + 1>(is, t);
    }
    return is;
}
template <class... T>
istream &operator>>(istream &is, tuple<T...> &t) {
    return cin_tuple_impl(is, t);
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << p.first << " " << p.second;
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    int s = (int)v.size();
    for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
    return os;
}
template<typename T, size_t N>
ostream &operator<<(ostream &os, const array<T, N> &v) {
    size_t n = v.size();
    for (size_t i = 0; i < n; i++) {
        if (i) os << " ";
        os << v[i];
    }
    return os;
}
template <size_t N = 0, typename T>
ostream& cout_tuple_impl(ostream &os, const T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) os << " ";
        const auto &x = std::get<N>(t);
        os << x;
        cout_tuple_impl<N + 1>(os, t);
    }
    return os;
}
template <class... T>
ostream &operator<<(ostream &os, const tuple<T...> &t) {
    return cout_tuple_impl(os, t);
}

void in() {}
template<typename T, class... U>
void in(T &t, U &...u) {
    cin >> t;
    in(u...);
}
void out() { cout << "\n"; }
template<typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
    cout << t;
    if (sizeof...(u)) cout << sep;
    out(u...);
}
void outr() {}
template<typename T, class... U, char sep = ' '>
void outr(const T &t, const U &...u) {
    cout << t;
    outr(u...);
}

void __attribute__((constructor)) _c() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
}
} // namespace io

using io::in;
using io::out;
using io::outr;

using ll = long long;
using D = double;
using LD = long double;
using P = pair<ll, ll>;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using vi = vector<ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
template <class T> using vvvc = vector<vvc<T>>;
template <class T> using vvvvc = vector<vvvc<T>>;
template <class T> using vvvvvc = vector<vvvvc<T>>;
#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
template<typename T> using PQ = priority_queue<T,vector<T>>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep1(a)          for(ll i = 0; i < a; i++)
#define rep2(i, a)       for(ll i = 0; i < a; i++)
#define rep3(i, a, b)    for(ll i = a; i < b; i++)
#define rep4(i, a, b, c) for(ll i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(a)          for(ll i = (a)-1; i >= 0; i--)
#define rrep2(i, a)       for(ll i = (a)-1; i >= 0; i--)
#define rrep3(i, a, b)    for(ll i = (b)-1; i >= a; i--)
#define rrep4(i, a, b, c) for(ll i = (b)-1; i >= a; i -= c)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define for_subset(t, s) for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define SZ(v) ll(v.size())
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(c, x) distance((c).begin(), lower_bound(ALL(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(ALL(c), (x)))
template <typename T, typename U>
T SUM(const vector<U> &v) {
    T res = 0;
    for(auto &&a : v) res += a;
    return res;
}
template <typename T>
vector<pair<T,int>> RLE(const vector<T> &v) {
    if (v.empty()) return {};
    T cur = v.front();
    int cnt = 1;
    vector<pair<T,int>> res;
    for (int i = 1; i < (int)v.size(); i++) {
        if (cur == v[i]) cnt++;
        else {
            res.emplace_back(cur, cnt);
            cnt = 1; cur = v[i];
        }
    }
    res.emplace_back(cur, cnt);
    return res;
}
template<class T, class S>
inline bool chmax(T &a, const S &b) { return (a < b ? a = b, true : false); }
template<class T, class S>
inline bool chmin(T &a, const S &b) { return (a > b ? a = b, true : false); }
void YESNO(bool flag) { out(flag ? "YES" : "NO"); }
void yesno(bool flag) { out(flag ? "Yes" : "No"); }

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int highbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int highbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int highbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int highbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T get_bit(T x, int k) { return x >> k & 1; }
template <typename T>
T set_bit(T x, int k) { return x | T(1) << k; }
template <typename T>
T reset_bit(T x, int k) { return x & ~(T(1) << k); }
template <typename T>
T flip_bit(T x, int k) { return x ^ T(1) << k; }

template <typename T>
T popf(deque<T> &que) { T a = que.front(); que.pop_front(); return a; }
template <typename T>
T popb(deque<T> &que) { T a = que.back(); que.pop_back(); return a; }
template <typename T>
T pop(queue<T> &que) { T a = que.front(); que.pop(); return a; }
template <typename T>
T pop(stack<T> &que) { T a = que.top(); que.pop(); return a; }
template <typename T>
T pop(PQ<T> &que) { T a = que.top(); que.pop(); return a; }
template <typename T>
T pop(minPQ<T> &que) { T a = que.top(); que.pop(); return a; }

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
    if (check_ok) assert(check(ok));
    while (abs(ok -  ng) > 1) {
        ll mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}
template <typename F>
ll binary_search_real(F check, double ok, double ng, int iter = 60) {
    for (int _ = 0; _ < iter; _++) {
        double mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return (ok + ng) / 2;
}

// max x s.t. b*x <= a
ll div_floor(ll a, ll b) {
    assert(b != 0);
    if (b < 0) a = -a, b = -b;
    return a / b - (a % b < 0);
}
// max x s.t. b*x < a
ll div_under(ll a, ll b) {
    assert(b != 0);
    if (b < 0) a = -a, b = -b;
    return a / b - (a % b <= 0);
}
// min x s.t. b*x >= a
ll div_ceil(ll a, ll b) {
    assert(b != 0);
    if (b < 0) a = -a, b = -b;
    return a / b + (a % b > 0);
}
// min x s.t. b*x > a
ll div_over(ll a, ll b) {
    assert(b != 0);
    if (b < 0) a = -a, b = -b;
    return a / b + (a % b >= 0);
}
// x = a mod b (b > 0), 0 <= x < b
ll modulo(ll a, ll b) {
    assert(b > 0);
    ll c = a % b;
    return c < 0 ? c + b : c;
}
// (q,r) s.t. a = b*q + r, 0 <= r < b (b > 0)
// div_floor(a,b), modulo(a,b)
pair<ll,ll> divmod(ll a, ll b) {
    ll q = div_floor(a,b);
    return {q, a - b*q};
}

struct Sieve{
    vector<bool> isprime;
    vector<int> minfactor;
    vector<int> mobius;
    Sieve(int n) : isprime(n+1,true), minfactor(n+1, -1), mobius(n+1,1){
        isprime[1] = false;
        minfactor[1] = 1;
 
        for(int i = 2; i <= n; i++){
            if(!isprime[i]) continue;
            minfactor[i] = i;
            mobius[i] = -1;
            for(int j = i+i; j <= n; j += i){
                isprime[j] = false;
                if(minfactor[j] == -1) minfactor[j] = i;
                if((j/i)%i == 0) mobius[j] = 0;
                else mobius[j] *= -1;
            }
        }
    }
 
    vector<pair<int, int>> factorize(int n){
        vector<pair<int, int>> res;
        while(n > 1){
            int p = minfactor[n];
            int e = 0;
            while(minfactor[n] == p){
                n /= p;
                e++;
            }
            res.push_back({p,e});
        }
        return res;
    }
 
    vector<int> divisor(int n){
        vector<int> res;
        res.push_back(1);
        auto v = factorize(n);
        for(auto x : v){
            int s = res.size();
            for(int i = 0; i < s; i++){
                int m = 1;
                for(int _ = 0; _ < x.second; _++){
                    m *= x.first;
                    res.push_back(res[i]*m);
                }
            }
        }
        return res;
    }
 
    template<class T> void fzt(vector<T> &f){
        int n = f.size();
        for(int p = 2; p < n; p++){
            if(!isprime[p]) continue;
            for(int q = (n-1)/p; q > 0; q--){
                f[q] += f[p*q];
            }
        }
    }
 
 
    template<class T> void fmt(vector<T> &f){
        int n = f.size();
        for(int p = 2; p < n; p++){
            if(!isprime[p]) continue;
            for(int q = 1; q*p < n; q++){
                f[q] -= f[p*q];
            }
        }

        // for(int p = 2; p < n; p++){
        //     if(!isprime[p]) continue;
        //     for(int q = (n-1)/p; q > 0; q--){
        //         f[p*q] -= f[q];
        //     }
        // }
    }
 
    template<class T> vector<T> conv(const vector<T> &f, const vector<T> &g){
        int n = max(f.size(), g.size());
        vector<T> nf(n), ng(n), h(n);
        for(int i = 0; i < (int)f.size(); i++) nf[i] = f[i];
        for(int i = 0; i < (int)g.size(); i++) ng[i] = g[i];
        fzt(nf); fzt(ng);
        for(int i = 0; i < n; i++) h[i] = nf[i]*ng[i];
        fmt(h);
        return h;
    }
};

int main() {
    string s; in(s);
    int n = s.size();
    Sieve si(n+5);
    int ans = n;
    int pe = 0;
    for(auto [p,e] : si.factorize(n)){
        int tmp = n;
        int d = n/p;
        rep(i,d){
            vector<int> f(26);
            for(int j = i; j < n; j += d){
                f[s[j]-'A']++;
            }
            tmp -= MAX(f);
        }
        if(chmin(ans,tmp)) pe = d;
    }
    string res = s;
    rep(i,pe){
        vector<int> f(26);
        for(int j = i; j < n; j += pe){
            f[s[j]-'A']++;
        }
        int c = max_element(ALL(f)) - f.begin();
        for(int j = i; j < n; j += pe){
            res[j] = char('A'+c);
        }
    }
    out(res);
}
0