QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21154. 和が7の倍数となる部分列

Statistics

Farmer John の $N$ 頭の牛は、時折そうするのが好きなように、一列に並んでいます。FJ が見分けられるよう、各牛には異なる整数の ID 番号が付いています。FJ は連続した牛の組を撮影したいのですが、幼いころ数字 $1 \ldots 6$ に関するつらい出来事を経験したため、ID の合計が $7$ の倍数になる組しか撮影したくありません。

FJ が撮影できる最大の組の大きさを求めてください。

入力

入力の最初の行には $N$($1 \leq N \leq 50,000$)が与えられます。続く $N$ 行には、それぞれ牛の $N$ 個の整数 ID が与えられます(すべて $0 \ldots 1,000,000$ の範囲です)。

出力

ID の合計が $7$ の倍数になる最大の連続した牛の組の頭数を出力してください。そのような組がない場合は 0 を出力してください。

大きな牛の組の ID の合計は、標準の 32 ビット整数に収まらない場合があることに注意してください。多数の ID を足す場合は、C/C++ の 64 ビット long long のような、より大きな整数型を使うとよいでしょう。

入出力例

入力 1

7
3
5
1
6
2
14
10

出力 1

5

注記

この例では、$5+1+6+2+14 = 28$ です。

問題作成:Brian Dean

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.