| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 200993 | model_code | Slon (COCI15_slon) | Cpython 2 | 253 ms | 35628 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
A = raw_input()
P, M = map(int, raw_input().strip().split(' '))
def mod (x):
return (x[0]%M, x[1]%M)
def sum (a, b):
return mod((a[0] + b[0], a[1] + b[1]))
def min (a, b):
return mod((a[0] - b[0], a[1] - b[1]))
def mul (a, b):
assert(not(a[0] > 0 and b[0] > 0))
return mod((a[0]*b[1] + a[1]*b[0], a[1]*b[1]))
def apply (ret, c):
if c == '+': tt = sum(ret[-2], ret[-1])
if c == '-': tt = min(ret[-2], ret[-1])
if c == '*': tt = mul(ret[-2], ret[-1])
ret.pop()
ret.pop()
ret.append(tt)
opp = {'+': 0, '-': 0, '*': 1}
os = []
ret = []
T = []
val = 0
ok = 0
for i in range(len(A)):
if A[i].isdigit():
val = val*10 + int(A[i])
ok = 1
else:
if ok: T.append(val)
val = 0
ok = 0
T.append(A[i])
if ok: T.append(val)
for c in T:
if c == 'x':
ret.append((1, 0))
elif c in opp:
while len(os) and (os[-1] in opp) and opp[os[-1]] >= opp[c]:
apply(ret, os[-1])
os.pop()
os.append(c)
elif c == '(': os.append(c)
elif c == ')':
while len(os) and os[-1] != '(':
apply(ret, os[-1])
os.pop()
assert(len(os) > 0)
os.pop()
else:
ret.append((0, c))
for c in os[::-1]:
apply(ret, c)
assert(len(ret) == 1)
ret = ret[0]
for i in range(0, 10**6):
if ((ret[0]*i + ret[1])%M + M)%M == P:
print i
break
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
