結果
問題 |
No.3001 ヘビ文字列
|
ユーザー |
![]() |
提出日時 | 2025-01-01 08:46:30 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,308 bytes |
コンパイル時間 | 3,805 ms |
コンパイル使用メモリ | 254,388 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-01-01 08:47:40 |
合計ジャッジ時間 | 68,331 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 54 WA * 9 TLE * 20 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:74:31: warning: 'c' may be used uninitialized [-Wmaybe-uninitialized] 74 | for(int k=j;k<n;k+=t) s[k]=c; main.cpp:67:10: note: 'c' was declared here 67 | char c; | ^ main.cpp:34:7: warning: 't' may be used uninitialized [-Wmaybe-uninitialized] 34 | 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>>; vector<ll> divisor(ll x){ set<ll> s; for(ll i=1;i*i<=x;i++){ if(x%i==0){ s.insert(i); s.insert(x/i); } } vector<ll> res; for(auto y:s) res.push_back(y); return res; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); string s; cin>>s; int n=s.size(); auto A=divisor(n); int a=A.size(); int mi=n+1; int t; rep(i,a){ int b=A[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; }