Logo
(追記) (追記ここまで)

11471번 - Fygon 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB84457.143%

문제

Frederick is a young programmer. He participates in all programming contests he can find and always uses his favorite programming language Fygon. Unfortunately, he often receives Time Limit Exceeded outcome, even when his algorithm is asymptotically optimal. That’s because the Fygon interpreter is very slow. Nevertheless, Frederick likes Fygon so much, that he uses non-asymptotical optimizations to fit the solution into time limit. To make it easier, he asks you to write a program, which will be able to estimate the exact number of operations that his Fygon program makes.

For simplicity, we will assume that Fygon has only two statements. The first statement is lag. It substitutes almost any other statement. The second statement is a for loop:

for <variable> in range (<limit>):
 <body>

This means that <variable> iterates over values from 0 to <limit>−1. In Fygon <variable> is a lowercase letter from a to z, and <limit> is either already defined <variable> or a positive integer constant. The <body> of the loop is indented by four spaces and contains at least one statement.

The program receives the input in the variable n. This variable has special meaning and cannot be used as a loop variable.

Your task is to find the formula that calculates the number of performed lag operations by the given Fygon program, depending on the value of the variable n.

입력

The input file contains the Fygon program. No two loops use the same variable as iterators. Each variable used inside a range is either n or declared in some outer loop.

The program has at most 20 statements and at most 6 of them are loops. All integer constants are from 1 to 9. Outpu

출력

Output the formula for the number of performed lag operations depending on n. The length of the formula should be at most 100 characters (excluding spaces). The formula should correspond to the following grammar:

⟨Expression⟩ ::= ⟨Product⟩ ( (‘+’ | ‘-’) ⟨Product⟩) *
 ⟨Product⟩ ::= ⟨Value⟩ (‘*’⟨Value⟩) *
 ⟨Value⟩ ::= ‘n’ | ⟨Number⟩ | ‘-’⟨Value⟩ | ‘(’⟨Expression⟩‘)’
 ⟨Number⟩ ::= [‘0’..‘9’] + (‘/’ [‘0’..‘9’] +) ?

제한

예제 입력 1

for i in range(n):
 for j in range(i):
 lag
for x in range(5):
 for y in range(n):
 for z in range(n):
 lag
 lag

예제 출력 1

1/2 * n * (n-1) + 5 * (n*n + 1)

힌트

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > NEERC Northern Subregional 2015 F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /