結果
問題 | No.539 インクリメント |
ユーザー | tktk_snsn |
提出日時 | 2021-01-17 22:53:25 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 699 ms / 2,000 ms |
コード長 | 1,044 bytes |
コンパイル時間 | 248 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 12,836 KB |
最終ジャッジ日時 | 2024-05-07 12:10:59 |
合計ジャッジ時間 | 2,572 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
10,880 KB |
testcase_01 | AC | 31 ms
11,264 KB |
testcase_02 | AC | 697 ms
12,704 KB |
testcase_03 | AC | 699 ms
12,836 KB |
ソースコード
from string import digits import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) T = int(input()) digits = set(list(digits)) for _ in range(T): S = input().rstrip() N = len(S) i = N - 1 prev = [] num = [] while i >= 0: if not S[i] in digits: prev.append(S[i]) i -= 1 else: if S[i] == "9": up = 1 num.append("0") else: up = 0 num.append(str(int(S[i])+1)) i -= 1 while i >= 0 and S[i] in digits: if up: if S[i] == "9": num.append("0") else: up = 0 num.append(str(int(S[i]) + 1)) else: num.append(S[i]) i -= 1 if up: num.append("1") break print(S[:i+1], end="") print("".join(num[::-1]), end="") print("".join(prev[::-1]))