問題一覧 > 通常問題

No.1765 While Shining

レベル : / AI推定難易度 : 950 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 156
作問者 : first_vil / テスター : 👑 箱星 ygussany
お気に入りにしたユーザー ProblemId : 7203 / 自分の提出
問題文最終更新日: 2021-11-26 14:45:58
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 325 (順位表) の他の問題:

Problem Statement

There is a grid of $N$ cells arranged in a horizontal row. The $i$-th cell from the left is called cell $i$. Initially, cell $i$ is shining if $A_i=1$, and is not shining if $A_i=0$.

You will now place a robot on one of the cells. The placed robot repeatedly performs the following sequence of actions.

  1. If the current cell is cell $N$ or is not shining, stop operating.
  2. Move to the cell $1$ to the right, then invert the "shining" / "not shining" state of all cells.

For each cell, find the number of times the robot moves when it is placed on that cell, and output the sum of these values.

Input

$N$
$A_1$ $A_2$ $\dots$ $A_N$
  • All inputs are integers.
  • $1 \le N \le 2 \times 10^5$
  • $0 \le A_i \le 1$

Output

Output the sum of the number of times the robot moves, followed by a newline.

Sample

Sample 1
Input
5
1 1 1 0 1
Output
4

If the robot is placed on cell $1$ or cell $2$, then immediately after it moves $1$ time, the current cell changes to the not shining state, so it stops at the cell $1$ to the right.

If the robot is placed on cell $3$, then immediately after each move, the current cell changes to the shining state, so it reaches cell $5$.

Sample 2
Input
8
0 1 0 1 1 0 0 1
Output
6

Sample 3
Input
15
0 0 0 1 1 0 0 0 1 0 1 0 0 1 1
Output
10

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。