Problem:


Score : 500 points

Problem Statement

We have N bulbs arranged on a number line, numbered 1 to N from left to right.
Bulb i is at coordinate i.

Each bulb has a non-negative integer parameter called intensity.
When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.
Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:

For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.

Find the intensity of each bulb after the K operations.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq K \leq 2 \times 10^5

0 \leq A_i \leq N

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:

A{'}_1 A{'}_2 \ldots A{'}_N

Sample Input 1

5 1
1 0 0 1 0

Sample Output 1

1 2 2 1 2 

Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.
Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.

Sample Input 2

5 2
1 0 0 1 0

Sample Output 2

3 3 4 4 3 



Sample input:
5 1
1 0 0 1 0


Sample output:
1 2 2 1 2

Submission status: Wrong Answer

Solution code:
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
#from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = 998244353
#from decimal import Decimal

n,k=mdata()
A=mdata()
ind=[INF]*n
t=-INF
for i in range(n):
    ind[i] = min(ind[i], abs(t - i))
    if A[i]==1:
        t=i

t=INF
for i in range(n-1,-1,-1):
    ind[i] = min(ind[i], abs(t - i))
    if A[i]==1:
        t=i

A1=[0]*n
if k==1:
    A1=[1]*n
    for i in range(n):
        if i>0:
            A1[i]+=A[i-1]
        if i<n-1:
            A1[i]+=A[i+1]
else:
    for i in range(n):
        if i+k>=n:
            A1[i]+=n-i-1
        else:
            A1[i]+=k-1
            if ind[i+k]<k:
                A1[i]+=1
        if i-k<0:
            A1[i]+=i
        else:
            A1[i] += k - 1
            if ind[i - k] < k:
                A1[i] += 1
        A1[i]+=1
print(*A1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

##### 進数の変換 #####
# bin_str = bin(i)[2:]
# oct_str = oct(i)[2:]
# hex_str = hex(i)[2:]

##### とても大きな数 と 小数の計算誤差 #####
# 「Decimal」は計算誤差を 0にできる。必要に応じて粒度を設定せよ。
# getcontext().prec = 100
#
# tmp = Decimal(i)
# A,B = map(Decimal, input().split())
# ans = A * B

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,K = inputMap()
	A = inputList()

	if max(A) > 100000:
		T = [K for i in range(N)]
		print(*T)
		sys.exit()

	for j in range(K):
		T = [0 for i in range(N)]
		for i,val in enumerate(A):
			#print(T)
			tmp_min = max(0,i-val)
			T[tmp_min] += 1

			if i+val+1 > N-1:
				continue
			tmp_max = min(N-1,i+val+1)
			T[tmp_max] -= 1

		for i,val in enumerate(T):
			if i == 0:
				continue
			T[i] += T[i-1]
		A = T

	print(*A)



def segfunc(x, y):
    return 0

ide_ele = float('inf')

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索のリバース
def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索
# 存在しない場合: None 存在する場合: その値
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import copy
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0 for _ in range(n)]
for v in range(k):
  for i in range(n):
    for j in range(max(1,i+1-a[i]),min(n,i+1+a[i])+1):
      b[j-1]+=1
  
  a=copy.deepcopy(b)
  b=[0 for _ in range(n)]
print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, K = map(int, input().split(' '))
A = tuple(map(int, input().split(' ')))

dp = np.zeros(shape=N + 1, dtype=np.int64)

if K >= 30:
    A = [N for _ in range(N)]
else:
    for k in range(K):
        for i in range(N):
            dp[max(0, i - A[i])] += 1
            dp[min(N, i + A[i] + 1)] -= 1
        A = dp.cumsum()[:-1]
        if np.all(A == N):
            break
        dp *= 0

print(' '.join(map(str, A)))

Submission status: Wrong Answer

Solution code:
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(k):
  b=[0]*n
  for j in range(n):
    if a[j]<max(n-j-1,j):
      break
  else:
    print('n '*n)
    sys.exit()
  if k-i>n-2:
    print('n '*n)
    sys.exit()
  for j in range(n):
    for m in range(j-a[j],j+a[j]+1):
      if 0<=m<=n-1:
        b[m]=b[m]+1
  a=b
for i in a:
  print(i,end=' ')

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
endA = [N]*N
for i in range(K):
    if A == endA:
        break;
    else:
        newA = [0]*N
        for j in range(N):
            for k in range(2*A[j]+1):
                if 0<=j-A[j]+k and j-A[j]+k <N:
                    newA[j-N+k] += 1
        A = newA
print(A)

Submission status: Wrong Answer

Solution code:
num_bulb, count = map(lambda x: int(x), input().split())
brightness = list(map(lambda x: int(x), input().split()))

for i in range(count):
    next_brightness = []
    # それぞれの電球について
    for j in range(num_bulb):
        next_brightness.append(0)
        # それをテラス電球を調べる
        for k in range(num_bulb):
          if abs(j - k) < brightness[k] + 0.5:
            next_brightness[j] += 1

print(' '.join(list(map(lambda x: str(x), next_brightness))))

Submission status: Wrong Answer

Solution code:
import copy
N,K = map(int,input().split())
while True:
    try:
        listA=list(map(int,input().split()))
    except:
        break;
print(N,K)
        
for iter in range(K):
  lit_list=[0]*N
  for i in range(N): #i:確かめるインデックス
    for j in range(N): #ライトの位置
      if abs(i-j)<=listA[j]:
        lit_list[i]+=1
  listA=copy.deepcopy(lit_list)

print(listA)

Submission status: Wrong Answer

Solution code:
[n, k] = raw_input().split()
a = raw_input().split()
A = []
n = int(n)
k = int(k)
for i in a:
    A.append(int(i))
for i in range(k):
    t = [0] * n
    for j in range(n):
        for k in range(j - A[j], j + A[j] + 1):
            if k<0 or k>n-1: continue
            t[k] += 1
    A = t[:]
print A

Submission status: Wrong Answer

Solution code:
import math

N, K = map(int, input().split())
A = [int(s) for s in input().split()]

for i in range(K):
  B = [0] * N
  for j in range(N):
    s = math.ceil(j - A[j] - 0.5)
    e = math.ceil(j + A[j] + 0.5)
    if s < 0:
      s = 0
    if e > N:
      e = N
    for k in range(s,e):
      B[k] += 1
  A = B
print(A)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
dp = list(map(int,input().split()))
if k > 19:
  ans = [n for _ in range(n)]
  print(*ans)
else:
  for i in range(k):
    ndp = [0 for _ in range(n)]
    for j in range(n):
      for l in range(j-dp[j],j+dp[j]+1):
        if 0 <= l < n:
          ndp[l] += 1
    dp = ndp[:]
  print(*dp)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

for k in range(K):
    B = np.zeros(N)
    for i in range(N):
        B[int(max(0, i - A[i])):int(min(i + A[i], N - 1))] += 1
    A = B

for a in A:
    print(int(a), end=" ")
print()

Submission status: Wrong Answer

Solution code:
import sys

nb, k = map(int, input().split())
lst = [int(n) for n in input().split()]
if sum(lst) == 0:
    print(*lst)
    sys.exit()

# 1 0 0 1 0
# 1 2 2 1 2
# 3 3 4 4 3
# 5 5 5 5 5


def clamp(a, b, c):
    return sorted([a, b, c])[1]


for _ in range(k):
    new = [0] * len(lst)
    for i, n in enumerate(lst):
        for j in range(max(0, i - n), min(i + n + 1, len(lst))):
            new[j] += 1

    if new == lst:
        print(*new)
        break
    lst = new
else:
    print(*lst)

Submission status: Wrong Answer

Solution code:
import copy as cp
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(K):
  B = [0 for i in range(N)]
  for i in range(N):
    for j in range(N):
      if j+A[j] >= i and j-A[j] <= i:
        B[i] += 1
	
  A = cp.copy(B)

print(A)

Submission status: Wrong Answer

Solution code:
l1= input().split(' ')
n= int(l1[0])
k= int(l1[1])

start= input().split(' ')

def f(ar, n):
	new= [0]*n
	for index in range(n):
		d= int(start[index])
		try:
			for k in range(index-d, index+d+1):
				new[k]+=1
		except:
			try:
				for k in range(index-d, n):
					new[k]+=1
			except:
				try:
					for k in range(0, index+d+1):
						new[k]+=1
				except:
					for k in range(0, n):
						new[k]+=1
	return new

'''
		if index-d<0:
			if index+d>len(ar)-1:
				for k in range(0, n):
					new[k]+=1
			else:
				for k in range(0, index+d+1):
					new[k]+=1
		elif index+d>len(ar)-1:
			for k in range(index-d, n):
				new[k]+=1
		else:
			for k in range(index-d, index+d+1):
				new[k]+=1
	return new
'''

for _ in range(0,k):
	start= f(start, n)
print(*start, sep=' ')

Submission status: Wrong Answer

Solution code:
#import numpy as np
N,K=map(int, input().split())

A=list(map(int, input().split()))
K=min(K, 30)
for k in range(K):
    B=[0]*(N+1)
    for i in range(N):
        a=A[i]
        start=max(0,i-a)
        end=min(N,i+a+1)
        B[start]+=1
        B[end]-=1
    #B=np.array(B)
    A=[0]*N
    A[0]=B[0]
    for i in range(1,N):
        A[i]=A[i-1]+B[i]

    if min(A)==N:
        break
    #print(B)
    
    
print(*A)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

# for _ in range(k):
#     next_a = [0] * n
#     for i, brightness in enumerate(a):
#         begin = max(0, i - brightness)
#         end = min(i + brightness + 1, n)
#         for j in range(begin, end):
#             next_a[j] += 1
#     print(next_a)
#     a = next_a.copy()

for _ in range(k):
    stack = []
    for i, brightness in enumerate(a):
        begin = i - brightness - 0.5
        end = i + brightness + 0.5
        stack.append((begin, "IN"))
        stack.append((end, "OUT"))
    stack.sort(key=lambda x: x[0])
    # print(stack)
    now = 0
    pos = 0
    for inout in stack:
        if pos > n-1:
            break
        while pos < inout[0]:
            if pos > n-1:
                break
            a[pos] = now
            pos += 1
        if inout[1] == "IN":
            now += 1
        elif inout[1] == "OUT":
            now -= 1
print(a)

Submission status: Wrong Answer

Solution code:
input1 = list(map(int, input().split()))
A = list(map(int, input().split()))

N = input1[0]
K = input1[1]

for k in range(K):
    B = [0] * N
    for i in range(1, N + 1):
        l_min = i - A[i - 1] - 0.5
        l_max = i + A[i - 1] + 0.5
        for j in range(1, N + 1):
            if(j >= l_min and j <= l_max):
                B[j - 1] += 1
    
    for x in range(N):
        A[x] = B[x]

print(A)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split(' ')))
A=list(map(int,input().split(' ')))
A2=A
if N<(K+1)*(K+2)/2:
    print([N]*N)
    exit()
for i in range(K):
    A=A2
    A2=[0]*N
    for i in range(len(A)):
        d=A[i]
        for j in range(d+1):
            if i-j>=0 and j>0:
                A2[i-j]=A2[i-j]+1
            if i+j<N:
                A2[i+j]=A2[i+j]+1
    if A2==[N]*N:
        print([N]*N)
        exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().rstrip().split())
As = [int(x) for x in input().rstrip().split()]
ret = []
for x in range(K):
    ret = []
    for y in range(len(As)):
        add = 0
        for z in range(len(As)):
            if abs(y - z) <= As[z]:
                add += 1
        ret.append(add)
    As = ret[:]
print(ret)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
flag = 0
light = [0]*n
for i in range(k):
    light = [0]*n
    for j in range(n):
        light[j] += 1
        for x in range(a[j]):
            try:
                if j - (x+1) < 0:continue
                light[j-(x+1)] += 1
            except IndexError:
                pass
        for x in range(a[j]):
            try:
                if j + (x+1) < 0:continue
                light[j+x+1] += 1
            except IndexError:
                pass
    if len(set(light)) == 1:
        break
    a = light
for i in range(n):
    print(light[i],end=' ')

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
Ai = input().split()
Bi = [int(i) for i in Ai]

if K >= N:
    li = [N for i in range(N)]
else:
    for n in range(K):
        li = [0 for i in range(N)]
        for i,x in enumerate(Bi):
            li[i] += 1
            for l in range(1,x+1):
                if i - l >= 0:
                    li[i-l] += 1
                if i + l <= N - 1:
                    li[i+l] += 1
        Bi = li
    print(li)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
import itertools

N, K = map(int, input().split())
An = list(map(int, input().split()))

#Sn = np.array([[0 for i in range(N)] for i in range(N)])#照らしている範囲
Fn = [[i for i in range(max(0,i - An[i]), min(i + An[i] + 1, N))] for i in range(N)]#照らしている電球(index)
#Bn = np.array([0 for i in range(N)])

#for i in range(N):
    #Sn[i][max(0,i - An[i]): min(i + An[i] + 1, N)] = 1
    #Fn[i] += [i for i in range(max(0,i - An[i]), min(i + An[i] + 1, N))]
    #Bn[max(0,i - An[i]): min(i + An[i] + 1, N)] += 1

#print(Sn)
#print(Fn)

for k in range(K):
    pre_An = An.copy()
    #An = [sum(Sn[:,i]) for i in range(len(An))]
    Fn_flat = list(itertools.chain.from_iterable(Fn))
    An = [Fn_flat.count(i) for i in range(len(An))]
    Fn = [[i for i in range(max(0,i - An[i]), min(i + An[i] + 1, N))] for i in range(N)]
    #print(Bn-An)
    #An = Bn
    #Bn = np.array([0 for i in range(N)])
    #for i in range(N):
        #Sn[i][max(0,i - An[i]): min(i + An[i] + 1, N)] = 1
        #Bn[max(0,i - An[i]): min(i + An[i] + 1, N)] += 1
print(An)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    if (k>18):
        ans = [n]*n
        print(*ans)
        exit()
    #print(tnp)
    for i in range(k):
        b = [0]*n
        for i in range(n):
            l = i-a[i]
            r = i+a[i]
            #print(l,r)
            b[max(l,0)] += 1
            if (r<n-1):
                b[r+1] -= 1
            #print(b)
    
        for i in range(1,n):
            b[i] = b[i-1] + b[i]
        a = b
        
    print(*b)
    
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K > N:
    B = [N]*N
else:
    for _ in range(K):
        B = [0] * N
        for i in range(N):
            if A[i] > 0:
                if (A[i] > N - 1):
                    B = list(map(lambda x: x+1, B))
                else:
                    B[i] += 1
                    for j in range(A[i]):
                        if (i - j - 1 >= 0):
                            B[i-j-1] += 1
                        if (i + j + 1 < N):
                            B[i+j+1] += 1
        A = B

for _ in B:
    print(_, end=' ')

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import copy
input=sys.stdin.readline
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    lighted = np.array([0]*N)
    for i,a in enumerate(A):
        area = len(lighted[max(0,i-a):min(i+a,N-1)+1])
        lighted[max(0,i-a):min(i+a,N-1)+1] += np.array([1]*area)
    
    for _ in range(K-1):
        tmp = np.array([0]*N)
        for i,a in enumerate(lighted):
            area = len(tmp[max(0,i-a):min(i+a,N-1)+1])
            tmp[max(0,i-a):min(i+a,N-1)+1] += np.array([1]*area)
        lighted = copy.deepcopy(tmp)
        if lighted[0] == N:
            break
    print(lighted)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
  
a=[0]*n
ans=[0]*n
a=list(map(int,input().split()))
check=math.ceil(math.log2(n))+1
if (k>=check):
  a=[n]*n
  print(" ".join(map(str,a)))
else:
  for _ in range(k):
    ans=[0]*n
    for i in range(n):
      left=max(0,i-a[i])
      right=min(n-1,i+a[i])
      #print(left,right)
      for j in range(left,right+1):
        ans[j]+=1
    a=ans

  print(" ".join(map(str,a)))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    if (k>18):
        print([n]*n)
        exit()
    #print(tnp)
    for i in range(k):
        b = [0]*n
        for i in range(n):
            l = i-a[i]
            r = i+a[i]
            #print(l,r)
            b[max(l,0)] += 1
            if (r<n-1):
                b[r+1] -= 1
            #print(b)
    
        for i in range(1,n):
            b[i] = b[i-1] + b[i]
        a = b
        
    print(*b)
    
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    print(1)
else:
    cnt = 1
    while 2 ** (cnt-1) < N:
        cnt += 1
    cnt += 1
    if cnt <= K:
        ans = [N]*N
        print(" ".join(map(str,ans)))
    else:
        old = np.array(A)
        for _ in range(K):
            Next = np.zeros(N,dtype = np.int64)
            for i in range(N):
                a = old[i]
                MIN = max(0,i-a)
                MAX = min(N-1,i+a)
                Next[MIN:MAX+1] += 1
            old = Next
        old = list(old)
        print(" ".join(map(str,old)))

Submission status: Wrong Answer

Solution code:
import heapq
import numpy as np
import bisect
n, k = [int(x) for x in input().split()]
s = np.array([int(x) for x in input().split()])
origin = np.array([i for i in range(n)])
dif = np.array([0.5 for i in range(n)])

t1, t2 = 0, 0

for i in range(k):
  t1 = origin-s-dif
  t2 = origin+s+dif
  t1.sort()
  t2.sort()
  tmp = 0
  for j in range(n):
    _1 = bisect.bisect_right(t1, j)
    _2 = bisect.bisect_right(t2, j)
    t1, t2 = t1[_1:], t2[_2:]
    tmp = tmp + _1 -_2
    s[j] = tmp

print(s)

Submission status: Wrong Answer

Solution code:
A = [1,0,0,1,0]
N = 5
K = 9
endA = [N]*N
for i in range(K):
    if A == endA:
        break;
    else:
        newA = [0]*N
        for j in range(N):
            for k in range(2*A[j]+1):
                if 0<=j-A[j]+k and j-A[j]+k <N:
                    newA[j-N+k] += 1
        A = newA
print(A)

Submission status: Wrong Answer

Solution code:
import copy as cp

N, K =map(int, input().split())
A = [int(i) for i in input().split()]

threshold = 18

if K > threshold:
    A = [N]*N
else:
    for i in range(K):
        A_old = cp.deepcopy(A)
        A = [0]*N
        starts = [0]*N
        ends = [0]*N
        for j in range(N):
            elem = A_old[j]
            starts[max(j-elem, 0)] += 1
            ends[min(j + elem, N-1)] += 1
        now = 0
        for j in range(N):
            now += starts[j]
            A[j] += now
            now -= ends[j]
            
print(*A)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
res = list(map(int,input().split()))
if K>=38:
    res = [N]*N
else:
    for k in range(K):
        delta = np.zeros((N+1), dtype=np.int64)
        for i,val in enumerate(res):
            left = max(0, i-val)
            right = min(N-1, i+val)
            delta[left] += 1
            delta[right+1] -= 1
        res = np.cumsum(delta, dtype=np.int64)[:N]
        if res.sum() >= N**2:
            break
print(*res)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
old=[0]*n
def hantei(a,b):
    for i in range(n):
        if a[i] != b[i]:
            return False
    return True

for _ in range(k):
    if hantei(a,old):
        break
    temp = [0]*n
    for i in range(n):
        start,goal = i-a[i], i+a[i]+1
        for j in range(start,goal):
            if 0<=j<n:
                temp[j]+=1
    old=a[:]
    a=temp[:]

for val in a:
    print(val, end=" ")

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
b=0
for _ in range(K):
    B=[]
    for i in range(len(A)):
        for j in range(len(A)):
            if A[j]-abs(i-j)>=0:
                b+=1
        B.append(b)
        b=0
    A=B
print(A)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,K = map(int,input().split())
a = list(map(int,input().split()))

for k in range(K):
    light = [0]*n
    st = [0]*n
    skip = True
    for i in range(n):
        if i - a[i] >= 0:
            light[i-a[i]] += 1
        else:
            light[0] += 1
        
        if i + a[i] + 1 <= n-1:
            light[i + a[i] + 1] -= 1

    st[0] = light[0]
    if st[0] < n-1:
        skip = False
    for i in range(1,n):
        st[i] = st[i-1] + light[i]    
        if st[i] < min(n-1-i,i):
            skip = False
    
    if skip:
        for _ in range(n):
            print(n, end = " ")
        exit()
    
    a = st
for ans in a:
    print(ans, end = " ")

Submission status: Wrong Answer

Solution code:
N = 5
K = 10000000000000
A = [1, 0, 0, 1, 0]


#import numpy as np
#A = np.array(A, dtype=int)
lenA = len(A)
for i in range(K):
#    B = np.zeros(lenA, dtype=int)
    B = [0 for _ in range(lenA)]
#    print(B)
    for j in range(lenA):
        num = A[j]
#        print(j, num)
#        B[max(0, j - num): min(lenA, j + num + 1)] += 1
        B[max(0, j - num): min(lenA, j + num + 1)] = [b + 1 for b in B[max(0, j - num): min(lenA, j + num + 1)]]
#        print(j, B)
    if all([a == b for a, b in zip(A,B)]):
#        print('same')
        break
    else:
        A = B
print(' '.join(map(str, A)))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
if a==[0]*n:
    print(*a)
else:
    print(*[n]*n)

Submission status: Wrong Answer

Solution code:

import copy

n,k = map(int, input().split())
num_list = list(map(int, input().split()))
num_list.insert(0,0)

for i in range(0,k):
    arr = [0]*(n+1)
    for j in range(1,n+1):
        # print(j)
        a = j - num_list[j]
        if a < 0:
            a = 0
        b = j + num_list[j]
        if b > n:
            b = n
        # print(a,b)
        for k in range(a,b+1):
            arr[k] += 1 
    # print(i, arr)
    num_list = copy.deepcopy(arr)
    num_list[0] = 0
    # print(num_list)
    
print(arr[1:])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=[0 for e in range(n)]
for _ in range(k):
    for i in range(len(a)):
        if(i-a[i]>=0):
            if(i+a[i]<n):
                ans[i-a[i]:i+a[i]+1]=map(lambda x: x+1, ans[i-a[i]:i+a[i]+1])
            else:
                ans[i-a[i]:n]=map(lambda x: x+1, ans[i-a[i]:n])
        else:
            if(i+a[i]<n):
                ans[0:i+a[i]+1]=map(lambda x: x+1, ans[0:i+a[i]+1])
            else:
                ans[0:n]=map(lambda x: x+1, ans[0:n])

    a=ans
    ans=[0 for e in range(n)]
print(a)

Submission status: Wrong Answer

Solution code:
import copy as cp

N, K =map(int, input().split())
A = [int(i) for i in input().split()]

threshold = 20

if K>threshold:
    A = [N]*N
else:
    for i in range(K):
        A_old = cp.deepcopy(A)
        A = [0]*N
        starts = [0]*N
        ends = [0]*N
        for j in range(N):
            elem = A_old[j]
            starts[max(j-elem, 0)] += 1
            ends[min(j + elem, N-1)] += 1
        now = 0
        for j in range(N):
            now += starts[j]
            A[j] += now
            now -= ends[j]
            
print(*A)