CF803B.Distances to Zero

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given the array of integer numbers _a_0, _a_1, ..., a__n - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.

给你一个整数数组 a0,a1,…,an−1a_0, a_1, \dots, a_{n-1}。对每个元素,求其到最近的零元素(即值为 0 的元素)的距离。给定数组中至少包含一个零元素。

输入格式

The first line contains integer n (1 ≤ n ≤ 2·105) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 109 ≤ a__i ≤ 109).

第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 数组 aa 的长度。
第二行包含数组的整数元素,各元素之间以单个空格分隔(−109≤ai≤109-10^9 \leq a_i \leq 10^9)。

输出格式

Print the sequence _d_0, _d_1, ..., d__n - 1, where d__i is the difference of indices between i and nearest j such that a__j = 0. It is possible that i = j.

输出序列 d0, d1, ..., dn−1d_0, d_1, ..., d_{n-1},其中 did_i 表示下标 ii 与满足 aj=0a_j = 0 的最近下标 jj 之间的下标差值(即 ∣i−j∣|i - j|)。注意,ii 和 jj 可能相等。

输入输出样例

  • 输入#1

    9
    2 1 0 3 0 0 3 2 4

    输出#1

    2 1 0 1 0 0 1 2 3
  • 输入#2

    5
    0 1 2 3 4

    输出#2

    0 1 2 3 4
  • 输入#3

    7
    5 6 0 1 -2 3 4

    输出#3

    2 1 0 1 2 3 4

输入解题思路,AI测评打分。不知道怎么写?

首页