結果
| 問題 | No.1455 拡張ROTN |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-28 00:51:31 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 2,000 ms |
| コード長 | 1,052 bytes |
| コンパイル時間 | 180 ms |
| コンパイル使用メモリ | 82,816 KB |
| 実行使用メモリ | 52,864 KB |
| 最終ジャッジ日時 | 2024-07-05 08:52:17 |
| 合計ジャッジ時間 | 2,101 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
import sys
readline = sys.stdin.readline
S = readline().rstrip()
N = int(readline())
# 既に処理したことがあるものはdicに登録しておく
dic = {}
ans = []
def rotate_char(c, M):
rot = M % 26
if c.upper() == c: # 大文字の場合
return chr((ord(c) - ord('A') + rot) % 26 + ord('A'))
else:
return chr((ord(c) - ord('a') + rot) % 26 + ord('a'))
# CpCzNkSuTbEoAを0~25回rotateすると何になるかを求めておく
bef = [""] * 26
T = "CpCzNkSuTbEoA"
for i in range(26):
temp = []
for t in T:
temp.append(rotate_char(t, i))
bef[i] = "".join(temp)
for s in S:
if s in dic:
ans.append(dic[s])
continue
if s.isdigit():
# CpCzNkSuTbEoAになるまでに何回必要か
to_T = 10 - int(s)
if to_T > N: # CpCzNkSuTbEoAになれない
ans.append(str(int(s) + N))
continue
rest = N - to_T # 残りの試行回数
ans.append(bef[rest % 26])
else:
target = rotate_char(s, N)
dic[s] = target
ans.append(target)
print("".join(ans))