結果
| 問題 |
No.438 Cwwプログラミング入門
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-07 01:52:58 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,462 bytes |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-10-14 11:03:51 |
| 合計ジャッジ時間 | 6,298 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 97 RE * 1 |
ソースコード
#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# %%
x, y, z = map(int, read().split())
# %%
def simulate(code):
stack = []
for ch in code:
if ch == 'c':
stack.append(x)
elif ch == 'w':
stack.append(y)
elif ch == 'C':
a = stack.pop()
b = stack.pop()
stack.append(a + b)
elif ch == 'W':
a = stack.pop()
b = stack.pop()
stack.append(a - b)
else:
raise ValueError
return stack[-1]
def to_code(A, B):
if A == B == 0:
return 'ccW'
if A == 0 and B > 0:
return 'w' * B + 'C' * (B - 1)
if A > 0 and B == 0:
return 'c' * A + 'C' * (A - 1)
if A > 0 and B > 0:
return 'c' * A + 'w' * B + 'C' * (A + B - 1)
if A > 0 and B < 0:
return 'w' * (-B) + 'C' * (-B - 1) + 'c' * A + 'C' * (A - 1) + 'W'
if A < 0 and B > 0:
return 'c' * (-A) + 'C' * (-A - 1) + 'w' * B + 'C' * (B - 1) + 'W'
def solve(x, y, z):
for A in range(-5100, 5100):
if y == 0:
B = 0
else:
B = (z - A * x) // y
if A * x + B * y == z:
if 2 * (abs(A) + abs(B)) - 1 <= 10000:
return to_code(A, B)
return 'NO'
code = solve(x, y, z)
if code != 'NO':
assert simulate(code) == z
print(code)
maspy