結果
| 問題 |
No.3001 ヘビ文字列
|
| ユーザー |
👑 |
| 提出日時 | 2024-12-29 14:53:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 919 ms / 1,500 ms |
| コード長 | 635 bytes |
| コンパイル時間 | 1,086 ms |
| コンパイル使用メモリ | 82,340 KB |
| 実行使用メモリ | 160,944 KB |
| 最終ジャッジ日時 | 2025-01-01 07:44:12 |
| 合計ジャッジ時間 | 49,512 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 83 |
ソースコード
R=range
S=input()
N=len(S)
P=[];n=N
for i in R(2,int(n**0.5)+1):
c=0
while n%i<1:n//=i;c=1
if c:P+=[i]
if n>1:P+=[n]
opt = N + 1
for p in P:
d = N // p
opt_temp = 0
for i in R(d):
h = [0]*26
temp = 0
for j in R(p):
c = ord(S[i+j*d]) - ord('A')
h[c] += 1
temp = max( temp , h[c] )
opt_temp += p - temp
if opt > opt_temp:
opt = opt_temp
p_best = p
d = N // p_best
T=['A']*N
for i in R(d):
h = [0]*26
for j in R(p_best):h[ord(S[i+j*d]) - ord('A')] += 1
c_opt = -1
temp = 0
for c in R(26):
if temp < h[c]:
temp = h[c]
c_opt = c
for j in R(p_best):T[i+j*d] = chr(c_opt + ord('A'))
print("".join(T))