結果
問題 |
No.438 Cwwプログラミング入門
|
ユーザー |
![]() |
提出日時 | 2021-02-16 04:36:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,247 bytes |
コンパイル時間 | 228 ms |
コンパイル使用メモリ | 82,228 KB |
実行使用メモリ | 66,848 KB |
最終ジャッジ日時 | 2024-07-23 19:29:54 |
合計ジャッジ時間 | 13,117 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 59 WA * 37 RE * 2 |
ソースコード
def cww(s,x,y): st = [] for i in s: if i=="c": st.append(x) elif i=="w": st.append(y) elif i=="C": a = st.pop() b = st.pop() st.append(a+b) elif i=="W": a = st.pop() b = st.pop() st.append(a-b) else: assert 0 return st[-1] def extgcd(x,y): if y==0: return 1,0 #g=x r0,r1,s0,s1 = x,y,1,0 while r1 != 0: r0,r1, s0,s1 = r1,r0%r1, s1,s0-r0//r1*s1 return r0,s0,(r0-s0*x)//y from math import gcd x,y,z = map(int,input().split()) if x>y: x,y = y,x g,A,B = extgcd(x,y) if z%g: print("NO") exit() def ans(A,B): if abs(A)+abs(B) > 5000: return #print(A,B) if A >= 0 and B >= 0: s = "c"*A+"w"*B+"C"*(A+B-1) return s if A >= 0: B = -B s = "w"*B+"c"*A+"C"*(A-1)+"W"*B return s if B >= 0: A = -A s = "c"*A+"w"*B+"C"*(B-1)+"W"*A return s return None A *= z//g B *= z//g A %= y B = (z-A*x)//y assert A*x+B*y==z s = ans(A,B) if s: print(s) assert cww(s,x,y)==z exit() AA = A-y//g BB = B+x//g assert AA*x+BB*y==z s = ans(A,B) if s: print(s) assert cww(s,x,y)==z exit() print("NO")