結果
問題 |
No.3157 Nabeatsu
|
ユーザー |
![]() |
提出日時 | 2025-05-23 19:47:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 247 ms / 2,000 ms |
コード長 | 1,132 bytes |
コンパイル時間 | 581 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 218,276 KB |
最終ジャッジ日時 | 2025-05-23 19:47:11 |
合計ジャッジ時間 | 6,592 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
from collections import deque S=list(input()) d=deque() su=0 for s in S: su+=int(s) if '3' not in S and su%3!=0: print(''.join(S)) exit() if '3' in S: E=[] f=0;su=0 for s in S: if f==0: if s!='3': E.append(s) su+=int(s) else: E.append('2') f=1;su+=2 else: E.append('9') su+=9 if su%3==0: su-=1 m=int(E[-1])-1 E[-1]=str(m) print(''.join(E)) else: if S[-1]!='0': if S[-1]!='4': s=int(S[-1])-1 else: s=int(S[-1])-2 S[-1]=str(s) print(''.join(S)) else: E=deque() f=0;su=0 for s in S[::-1]: if f==0: if s=='0': E.append('9');su+=9 else: f=1 if s=='4': E.append('2');su+=2 else: g=int(s)-1 E.append(str(g));su+=g else: su+=int(s) E.append(s) while E and E[-1]=='0': E.pop() A=[] while E: A.append(E.pop()) if su%3!=0: print(''.join(A)) else: s=int(A[-1])-1 A[-1]=str(s) print(''.join(A))