QOJ.ac

QOJ

実行時間制限: 10 s メモリ制限: 256 MB 満点: 100

#23803. 一年級生

統計

題目描述

JOI 君係小學 $1$ 年級學生。JOI 君好鍾意啱啱學識嘅加法同減法,每逢見到一排數字嗰陣,佢就會喺最後 $2$ 個數字之間擺個 =,並喺其餘相鄰嘅數字之間一定擺 + 或者 -,整成等式嚟玩。例如,由 8 3 2 4 8 7 2 4 0 8 8 可以整出等式 8+3-2-4+8-7-2-4-0+8=8。

整好等式之後,JOI 君會計一次數嚟確證佢係咪一條正確嘅等式。不過,JOI 君仲未識負數,亦都唔識計大過 $20$ 嘅數。所以,喺正確嘅等式入面,只有由左至右計等號左邊嗰陣,中途出現嘅所有數都係 $0$ 以上 $20$ 以下嘅等式,先至係 JOI 君可以確證到嘅正確等式。例如,8+3-2-4-8-7+2+4+0+8=8 係一條正確嘅等式,但係因為中途出現嘅 8+3-2-4-8 係負數,所以 JOI 君確證唔到呢條等式啱唔啱。

畀定一列數字作為輸入,請寫一個程式求出 JOI 君可以整出並確證到嘅正確等式嘅數量。

輸入格式

輸入檔案有 $2$ 行。第 $1$ 行有一個整數 $N$($3 \le N \le 100$),代表排緊嘅數字數量。第 $2$ 行有 $N$ 個 $0$ 以上 $9$ 以下嘅整數,用空格隔開。

喺畀定嘅 $60\%$ 輸入數據入面,JOI 君可以整出並確證到嘅正確等式嘅數量唔超過 $2^{31}-1$。另外,喺所有畀定嘅輸入數據入面,JOI 君可以整出並確證到嘅正確等式嘅數量唔超過 $2^{63}-1$。

輸出格式

輸出 $1$ 行一個整數,代表 JOI 君可以整出並確證到嘅正確等式嘅數量。

範例

範例輸入 1

11
8 3 2 4 8 7 2 4 0 8 8

範例輸出 1

10

範例輸入 2

40
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1

範例輸出 2

7069052760

喺範例輸入 $1$ 入面,JOI 君可以整出並確證以下 $10$ 條正確嘅等式:

  • 8+3-2-4+8-7-2-4-0+8=8
  • 8+3-2-4+8-7-2-4+0+8=8
  • 8+3+2+4-8-7+2-4-0+8=8
  • 8+3+2+4-8-7+2-4+0+8=8
  • 8+3+2-4+8-7+2+4-0-8=8
  • 8+3+2-4+8-7+2+4+0-8=8
  • 8-3+2+4-8+7+2+4-0-8=8
  • 8-3+2+4-8+7+2+4+0-8=8
  • 8-3+2-4+8+7+2-4-0-8=8
  • 8-3+2-4+8+7+2-4+0-8=8

所以輸出 $10$。

喺範例輸入 $2$ 入面,請注意答案超出咗 $32$ 位元有符號整數嘅範圍。

($2015$ 年 $2$ 月 $21$ 日追記) 經用戶指出,發現範例輸入 $1$ 說明入面嘅等式有錯,而家已經修正好。第 $5$ 條等式原本係 8+3-2-4+8-7+2+4-0-8=8,已經修正做 8+3+2-4+8-7+2+4-0-8=8。另外,第 $6$ 條等式原本係 8+3-2-4+8-7+2+4+0-8=8,已經修正做 8+3+2-4+8-7+2+4+0-8=8。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.