結果

問題 No.438 Cwwプログラミング入門
ユーザー convexineqconvexineq
提出日時 2021-02-16 04:36:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,247 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 78,876 KB
最終ジャッジ日時 2023-10-01 01:58:25
合計ジャッジ時間 18,090 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,632 KB
testcase_01 AC 69 ms
71,292 KB
testcase_02 AC 68 ms
71,160 KB
testcase_03 AC 68 ms
71,620 KB
testcase_04 AC 71 ms
71,308 KB
testcase_05 AC 70 ms
71,324 KB
testcase_06 AC 69 ms
71,428 KB
testcase_07 AC 73 ms
71,376 KB
testcase_08 AC 68 ms
71,336 KB
testcase_09 AC 70 ms
71,396 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 71 ms
71,072 KB
testcase_14 AC 71 ms
71,272 KB
testcase_15 AC 71 ms
71,252 KB
testcase_16 AC 72 ms
71,652 KB
testcase_17 WA -
testcase_18 AC 71 ms
71,264 KB
testcase_19 AC 72 ms
71,288 KB
testcase_20 AC 71 ms
71,400 KB
testcase_21 AC 71 ms
71,080 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 71 ms
71,328 KB
testcase_25 AC 71 ms
71,504 KB
testcase_26 WA -
testcase_27 AC 70 ms
71,324 KB
testcase_28 AC 72 ms
71,400 KB
testcase_29 WA -
testcase_30 AC 71 ms
71,464 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 71 ms
71,400 KB
testcase_36 AC 75 ms
71,380 KB
testcase_37 AC 73 ms
71,400 KB
testcase_38 AC 72 ms
71,384 KB
testcase_39 AC 71 ms
71,344 KB
testcase_40 AC 71 ms
71,492 KB
testcase_41 AC 74 ms
71,324 KB
testcase_42 WA -
testcase_43 AC 73 ms
71,272 KB
testcase_44 AC 72 ms
71,248 KB
testcase_45 AC 73 ms
71,348 KB
testcase_46 AC 73 ms
71,340 KB
testcase_47 WA -
testcase_48 AC 79 ms
75,864 KB
testcase_49 WA -
testcase_50 AC 71 ms
71,648 KB
testcase_51 AC 75 ms
71,292 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 72 ms
71,348 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 70 ms
71,292 KB
testcase_59 AC 73 ms
75,840 KB
testcase_60 WA -
testcase_61 AC 71 ms
71,432 KB
testcase_62 AC 70 ms
71,376 KB
testcase_63 WA -
testcase_64 WA -
testcase_65 AC 72 ms
71,248 KB
testcase_66 WA -
testcase_67 AC 70 ms
71,636 KB
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 AC 71 ms
71,620 KB
testcase_79 AC 73 ms
71,500 KB
testcase_80 AC 69 ms
71,164 KB
testcase_81 AC 71 ms
71,300 KB
testcase_82 AC 70 ms
71,592 KB
testcase_83 AC 70 ms
71,596 KB
testcase_84 AC 70 ms
71,516 KB
testcase_85 AC 71 ms
71,392 KB
testcase_86 AC 72 ms
71,264 KB
testcase_87 AC 71 ms
71,300 KB
testcase_88 WA -
testcase_89 AC 75 ms
75,692 KB
testcase_90 AC 72 ms
71,264 KB
testcase_91 WA -
testcase_92 AC 71 ms
71,288 KB
testcase_93 RE -
testcase_94 RE -
testcase_95 AC 80 ms
75,984 KB
testcase_96 AC 73 ms
71,400 KB
testcase_97 WA -
testcase_98 AC 75 ms
71,280 KB
testcase_99 AC 75 ms
71,092 KB
testcase_100 AC 82 ms
75,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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")
0