結果
問題 |
No.3001 ヘビ文字列
|
ユーザー |
![]() |
提出日時 | 2025-01-01 09:05:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,348 bytes |
コンパイル時間 | 4,047 ms |
コンパイル使用メモリ | 255,196 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-01-01 09:05:48 |
合計ジャッジ時間 | 34,018 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 56 WA * 27 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:79:31: warning: 'c' may be used uninitialized [-Wmaybe-uninitialized] 79 | for(int k=j;k<n;k+=t) s[k]=c; main.cpp:72:10: note: 'c' was declared here 72 | char c; | ^ main.cpp:39:7: warning: 't' may be used uninitialized [-Wmaybe-uninitialized] 39 | 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]; 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; }