結果

問題 No.438 Cwwプログラミング入門
ユーザー ckawatak
提出日時 2019-04-21 23:01:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,449 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 82,268 KB
実行使用メモリ 64,276 KB
最終ジャッジ日時 2024-10-07 22:23:22
合計ジャッジ時間 8,924 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 98
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
from collections import deque

MAX = 10000

def solve0(z):
    return "ccW" if z == 0 else ""

def solve1(x, z, c):
    if z % x == 0:
        a = z // x
        if 2 * a - 1 <= MAX:
            return (c * a) + ('C' * (a-1))
    return ""

def solve2(x,y,z):
    for i in range(-MAX//2, MAX//2+1):
        b = i
        a = (z - y * b) // x
        if a * x + b * y == z:
            s = deque()
            if 0 < a:
                s.append('c')
                a = a - 1
            elif 0 < b:
                s.append('w')
                b = b - 1
            else:
                s.append('c')
                s.append('c')
                s.append('W')
            if len(s) + 2 * abs(a) + 2 * abs(b) <= MAX:
                for _ in range(abs(a)):
                    s.appendleft('c')
                    s.append('C' if 0 < a else 'W')
                for _ in range(abs(b)):
                    s.appendleft('w')
                    s.append('C' if 0 < b else 'W')
                return ''.join(s)
    return ""

X,Y,Z = list(map(int, input().split()))

code = ""
if len(code) == 0:
    code = solve0(Z)
if len(code) == 0:
    if X != 0:
        code = solve1(X, Z, 'c')
if len(code) == 0:
    if Y != 0:
        code = solve1(Y, Z, 'w')
if len(code) == 0:
    d = gcd(X, Y)
    if X != 0 and Y != 0 and Z % d == 0:
        code = solve2(X // d, Y // d, Z // d)
if len(code) == 0:
    code = "NO"
print(code)    
0