結果
| 問題 |
No.3001 ヘビ文字列
|
| ユーザー |
umezo
|
| 提出日時 | 2025-01-01 09:18:00 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 350 ms / 1,500 ms |
| コード長 | 1,257 bytes |
| コンパイル時間 | 3,472 ms |
| コンパイル使用メモリ | 256,232 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-01 09:18:28 |
| 合計ジャッジ時間 | 26,750 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 83 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:70:31: warning: 'c' may be used uninitialized [-Wmaybe-uninitialized]
70 | for(int k=j;k<n;k+=t) s[k]=c;
main.cpp:63:10: note: 'c' was declared here
63 | char c;
| ^
main.cpp:37:7: warning: 't' may be used uninitialized [-Wmaybe-uninitialized]
37 | int t;
| ^
ソースコード
#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) C.push_back(n/a);
int mi=n+1;
int t;
rep(i,m){
int b=C[i];
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;
}
umezo