結果

問題 No.3157 Nabeatsu
ユーザー timi
提出日時 2025-05-23 19:39:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 407 ms
コンパイル使用メモリ 81,984 KB
実行使用メモリ 218,368 KB
最終ジャッジ日時 2025-05-23 19:39:23
合計ジャッジ時間 6,228 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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':
    s=int(S[-1])-1
    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))
0