結果
| 問題 |
No.3001 ヘビ文字列
|
| ユーザー |
|
| 提出日時 | 2025-01-07 11:56:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,808 bytes |
| コンパイル時間 | 636 ms |
| コンパイル使用メモリ | 82,904 KB |
| 実行使用メモリ | 351,004 KB |
| 最終ジャッジ日時 | 2025-01-07 11:58:36 |
| 合計ジャッジ時間 | 144,360 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 24 WA * 10 TLE * 49 |
ソースコード
#!/usr/bin/env pypy3
def main():
s = input()
len_s = len(s)
is_prime = True
min_execution = 2000000
min_result = ""
for m in range(2, len_s):
if len_s % m == 0:
is_prime = False
n = len_s // m
unit_result = ""
concat_unit_result = ""
for i in range(m):
# A〜Z のカウント用配列 (0〜29 の30文字分)
unit = [0] * 30
for j in range(n):
# s[m*j + i] がどの文字かカウント
unit[ord(s[m*j + i]) - 65] += 1
# unit 配列内でカウントが最大の文字を探す
temp_max = 0
temp_index = 0
for k in range(30):
if unit[k] >= temp_max:
temp_max = unit[k]
temp_index = k
# 最大カウントの文字を部分文字列として追加
unit_result += chr(temp_index + 65)
# 上で求めた部分文字列を n 回繰り返し
concat_unit_result = unit_result * n
# 元の文字列 s との差分をカウント
count_difference = 0
for i in range(len_s):
if s[i] != concat_unit_result[i]:
count_difference += 1
# 差分が最小となるものを記録
if count_difference < min_execution:
min_execution = count_difference
min_result = concat_unit_result
# もし最初から割り切れる m がなければ s の長さは「素数」扱い
if is_prime:
result = s[0] * len_s
print(result)
else:
print(min_result)
if __name__ == "__main__":
main()