結果

問題 No.438 Cwwプログラミング入門
ユーザー ckawatak
提出日時 2019-04-20 16:54:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,538 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 82,764 KB
実行使用メモリ 708,108 KB
最終ジャッジ日時 2024-10-01 14:40:17
合計ジャッジ時間 21,847 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 35 RE * 17 TLE * 1 MLE * 2 -- * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

MAX = 100000000

def bsearch(min, max, target):
    while min < max:
        middle = (min + max) // 2
        if middle == target:
            return middle
        elif middle < target:
            min = middle + 1
        elif target < middle:
            max = middle -1
        else:
            return -1

def encode(p, q, negative):
    code = []
    
    count = p // 2
    rest = p % 2
    for i in range(count):
        code.append('c')
        code.append('c')
        code.append('C')
    if rest:
        if 2 < count:
            code.append('c')
            code.append('C')
        else:
            code.append('c')
    
    count = q // 2
    rest = q % 2
    for i in range(count):
        code.append('w')
        code.append('w')
        code.append('C')
    if rest:
        if 2 < count:
            code.append('w')
            code.append('C')
        else:
            code.append('w')
    
    if negative:
        code.append('W')
    else:
        code.append('C')
    
    return ''.join(code)
        
X,Y,Z = list(map(int, input().split()))

# p * X + q * Y = Z
coef = None
negative = False
for p in range(MAX+1):
    rest = Z - p * X
    if rest % Y == 0:
        target = rest // Y
        if target < 0:
            negative = True
        q = bsearch(0, MAX+1, abs(target))
        if q != -1:
            coef = (p,q)
            break
        
if coef:
    p,q = coef
    code = encode(p, q, negative)
    if 10000 < len(code):
        print('NO')
    else:
        print(code)
else:
    print('NO')
0