結果
| 問題 |
No.438 Cwwプログラミング入門
|
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2021-02-16 04:48:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 994 bytes |
| コンパイル時間 | 1,350 ms |
| コンパイル使用メモリ | 82,280 KB |
| 実行使用メモリ | 68,480 KB |
| 最終ジャッジ日時 | 2024-07-23 20:32:30 |
| 合計ジャッジ時間 | 9,089 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 2 |
| other | AC * 42 RE * 56 |
ソースコード
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")
convexineq