TopCoder

Caido
$\mathbb{W}\mathcal{aimai}\sim$

User's AC Ratio

87.0% (160/184)

Submission's AC Ratio

47.2% (265/561)

Tags

Description

小明的數學老師出了一題函數計算的家庭作業,由於筆算的過程非常複雜,請你寫一個程式協助小明以及班上的其他同學進行驗算,以確定計算的結果是正確的。老師所出的題目是這樣的:給定一個整數,請求出函數 $f$ 的值為何?

\[
f(x)=
\begin{cases}
f(x-1) - h(x) & \text{if } x > h(x) \\
f(g(x)) - g(x) & \text{if } x < h(x) \\
1 & \text{otherwise}
\end{cases}
\]
\[
h(y)=
\begin{cases}
-1 & \text{if } y < 2 \\
2 + h(y-1)-h(y-2) & \text{otherwise}
\end{cases}
\]
\[
g(z)=
\begin{cases}
z^2 - 1 & \text{if } z \leq 2 \\
2 & \text{otherwise}
\end{cases}
\]

Input Format

直接從標準輸入輸入一整數,$-300<x<300$。

Output Format

請將計算過後函數 $f$ 的值直接輸出至標準輸出。

Sample Input 1

3

Sample Output 1

-1

Sample Input 2

-2

Sample Output 2

-4

Sample Input 3

-21

Sample Output 3

-1307

Hints

Problem Source

原TIOJ1060 / 95北市賽(prob 2)

Subtasks

No. Testdata Range Score
1 0 14
2 1 14
3 2 14
4 3 14
5 4 14
6 5 14
7 6 16

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 262144 1
1 1000 65536 262144 2
2 1000 65536 262144 3
3 1000 65536 262144 4
4 1000 65536 262144 5
5 1000 65536 262144 6
6 1000 65536 262144 7