結果

問題 No.438 Cwwプログラミング入門
ユーザー convexineqconvexineq
提出日時 2021-02-16 04:50:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 54,484 KB
最終ジャッジ日時 2024-07-23 20:34:00
合計ジャッジ時間 7,694 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 98
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(x,y):
    if y==0: return x,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())
S = "cw"
if x>y:
    x,y = y,x
    S = "wc"


if z==0:
    print("ccW")
    exit()
if y==0:
    print("NO")
    exit()

g,A,B = extgcd(x,y)
if z%g:
    print("NO")
    exit()
x //= g; y //= g; z //= g


def ans(A,B):
    if abs(A)+abs(B) > 5000: return
    if A >= 0 and B >= 0:
        s = S[0]*A+S[1]*B+"C"*(A+B-1)
        return s
    if A >= 0:
        B = -B
        s = S[1]*B+S[0]*A+"C"*(A-1)+"W"*B
        return s
    if B >= 0:
        A = -A
        s = S[0]*A+S[1]*B+"C"*(B-1)+"W"*A
        return s
    return
A *= z; B *= z;
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
BB = B+x
#assert AA*x+BB*y==z
s = ans(AA,BB)
if s:
    print(s)
    #assert cww(s,x,y)==z
    exit()

print("NO")
0