結果

問題 No.3001 ヘビ文字列
ユーザー umezo
提出日時 2025-01-01 09:00:45
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,552 bytes
コンパイル時間 3,742 ms
コンパイル使用メモリ 257,104 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-01 09:01:18
合計ジャッジ時間 32,304 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 2
other AC * 12 WA * 71
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:90:31: warning: 'c' may be used uninitialized [-Wmaybe-uninitialized]
   90 |     for(int k=j;k<n;k+=t) s[k]=c;
main.cpp:83:10: note: 'c' was declared here
   83 |     char c;
      |          ^
main.cpp:50:7: warning: 't' may be used uninitialized [-Wmaybe-uninitialized]
   50 |   int t;
      |       ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;

map<ll,ll> prime_factor(ll x){
  map<ll,ll> res;
  
  for(ll i=2;i*i<=x;i++){
    while(x%i==0){
      res[i]++;
      x/=i;
    }
  }
  if(x!=1) res[x]++;
  
  return res;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  string s;
  cin>>s;
  int n=s.size();
  auto p=prime_factor(n);
  int m=p.size();
  V<int> C;
  for(auto [a,b]:p){
    int tmp=1;
    rep(j,b) tmp*=a;
    C.push_back(a);
  }
  V<int> D;
  for(int bit=1;bit<(1<<m);bit++){
    int tmp=1;
    rep(i,m){
      if(bit&&(1<<i)) tmp*=C[i];
    }
    if(tmp!=n) D.push_back(tmp);
  }
  int d=D.size();
  
  int mi=n+1;
  int t;
  rep(i,d){
    int b=D[i];
    if(b==n) continue;
    int cnt=0;
    rep(j,b){
      V<int> B(26);
      for(int k=j;k<n;k+=b){
        B[s[k]-'A']++;
      }
      int ma=0;
      rep(k,26) ma=max(ma,B[k]);
      bool f=false;
      rep(k,26){
        if(f==false && B[k]==ma){
          f=true;
        }
        else cnt+=B[k];
      }
      if(mi>cnt){
        mi=cnt;
        t=b;
      }
    }
  }
  
  rep(j,t){
    V<int> B(26);
    for(int k=j;k<n;k+=t){
      B[s[k]-'A']++;
    }
    int ma=0;
    rep(k,26) ma=max(ma,B[k]);
    char c;
    rep(k,26){
      if(B[k]==ma){
        c=char(k+'A');
        break;
      }
    }
    for(int k=j;k<n;k+=t) s[k]=c;
  }
  cout<<s<<endl;
    
  return 0;
}
0