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: Time Limit Exceeded

Solution code:
N, K= map(int,input().split())
A = list(map(int,input().split()))
p=0
while p<K:
  B=[0]*N
  for i in range(N):
    count = 0
    for j in range(N):
      #print(A[j])
      if A[j]+1>abs(j-i):
        count +=1
    #print(["A"]+A)  
    B[i] = count
    #print(["A"]+A)
    #print([B])
  A = B
  p +=1
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys

rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, k = rm()
a = rl()
for _ in range(k):
  li = [0] * n
  for i in range(n):
    s = max(i - a[i], 0)
    e = min(i + a[i], n-1)
    for m in range(s, e+1):
      li[m] += 1
  if a == li:
    break
  a = li
for v in a:
    print(v, end=' ')

Submission status: Time Limit Exceeded

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


class RAQ():
    
    def __init__(self, size):
        """初期化"""
        self.size = size
        n = 2 ** ((size-1).bit_length())
        treesize = n * 2
        st = [0] * treesize
        self.st = st
        self.offset = len(st) // 2

    @classmethod
    def from_array(cls, a):
        st = cls(len(a))
        for i, x in enumerate(a):
            st.add(i, i+1, x)
        return st

    def _add_topdown(self, a, b, value, k=1, l=0, r=-1):
        """区間[a, b) に対する加算
        k: 着目しているノード (1-indexed)
        l: 探索区間 st[l, r) の左端 (0-indexed)
        r: 探索区間 st[l, r) の右端 (0-indexed)
        """
        if r == -1:
            r = self.offset
        if r <= a or b <= l:
            return
        if l == r - 1:
            self.st[k] += value
            return
        if a <= l and r <= b:
            self.st[k] += value
            return
        mid = (l + r) // 2
        self._add(a, b, value, k * 2, l, mid)
        self._add(a, b, value, k * 2 + 1, mid, r)

    def _add_bottomup(self, a, b, value):
        """区間[a, b) に対する加算
        """
        a += self.offset
        b += self.offset - 1
        while a < b:
            if a & 1:
                self.st[a] += value
                a += 1
            a >>= 1
            if not b & 1:
                self.st[b] += value
                b -= 1
            b >>= 1
        if a == b:
            self.st[a] += value

    def add(self, a, b, value):
        """区間[a, b) に対する加算"""
        if a > b:
            raise ValueError("a must be less than equal b.")
        return self._add_bottomup(a, b, value)

    def get(self, key):
        """値の取得"""
        offset = len(self.st) // 2
        k = offset + key
        v = self.st[k]
        k >>= 1
        while k > 0:
            v += self.st[k]
            k >>= 1
        return v


def read():
    N, K = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, K, A


def solve(N, K, A):
    KL = int(math.log2(N) * 2) + 10
    if K > KL:
        print(' '.join([str(N)] * N))
        return
    raq = RAQ.from_array(A)
    a = [0 for i in range(N)]

    for k in range(min(K, KL)):
        for i in range(N):
            a[i] = raq.get(i)
            raq.add(i, i+1, -a[i])
        for i in range(N):
            l = max(0, i-a[i])
            r = min(N, i+1+a[i])
            raq.add(l, r, 1)
    print(' '.join([str(raq.get(i)) for i in range(N)]))


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Time Limit Exceeded

Solution code:
s = input().split()
N = int(s[0]) # 電球の数
K = int(s[1]) # 操作回数

A = list(map(int, input().split()))

for i in range(K):
    B = [1] * len(A)
    for j in range(N):
        if A[j] > 0:
            for k in range(1,A[j]+1):
                if j-k >= 0:
                    B[j-k] += 1
                if j+k < len(A):
                    B[j+k] += 1
    if A == B: 
        break
    else:
        A = B
    
print(*B)

Submission status: Time Limit Exceeded

Solution code:
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
count = 0
if k >= int(math.log10(k))+10:
  k = int(math.log10(k))

for i in range(k):
  for j in range(n):
    for m in range(n):
      if a[m] >= abs(m-j):
        b[j] += 1
  a = b  
  b = [0]*n
print(*a)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
As = list(map(int, input().split()))
lastAs = [n] * n


def change(arr):
  newAs = [0] * n
  flag = False
  for i, a in enumerate(arr):
    if (a >= n):
      flag = True
    for t in range(max(i - a, 0), min(i + a + 1, n)):
      newAs[t] += 1
  return (flag, newAs)


def clean(arr):
  newAs = [0] * n
  for i, a in enumerate(arr):
    newAs[i] = min(n, a)
  return newAs


def change2(arr):
  newAs = [0] * n
  flag = True
  for i, a in enumerate(arr):
    for t in range(max(i - a, 0), min(i + a + 1, n)):
      newAs[t] += 1
  for a in newAs:
    if (a < n):
      flag = False
  return (flag, newAs)


for temp in range(k):
  flag, As = change(As)
  if (flag):
    As = clean(As)
    for temp2 in range(min(k - temp), 3):
      flag2, As = change(As)
      As = clean(As)
      if (flag2):
        print(' '.join(map(str, As)))
        exit()
print(' '.join(map(str, As)))

Submission status: Time Limit Exceeded

Solution code:
import sys
N,K = map(int,input().split())
A = list(map(int,input().split()))
n = len(A)
fill = [0]*n
for z in range(K):
  i_count = [0]*n #座標iを照らすライトの数
  for i in range(1,n+1):
    light = A[i-1]
    for x in range(i-light,i+light+1):
      if x >= 1 and x <= n:
        i_count[x-1] += 1
        if i_count[x-1] == n:
          fill[x-1] = 1
          #print(fill)
  A = i_count
  if sum(fill) == n:
    break
print(*A, end=' ')

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))#光の強さ

co = [x for x in range(1,n+1)]#座標

while k > 0:
    temp = []
    for i in range(n):
        for i in range(int(co[i]-a[i]),int(co[i]+a[i]+0.5)+1):
            temp.append(i)
#    print(temp)
    counter = Counter(temp)
#    print(counter)
    a = []
    for i in range(1,n+1):
        a.append(counter[i])
    k -= 1

for i in a:
    print(i,end=' ')

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
l=[0]*n
c=[0]*n
l = input().split()
for i in range(n):
  l[i]=int(l[i])
  c[i]=0

for k in range(k):
  for i in range(n):
    c[i]+=1
    for j in range(1,l[i]+1):
      if -1<i-j<n:
        c[i-j]+=1
      if -1<i+j<n:
        c[i+j]+=1
  for i in range(n):
    l[i]=c[i]
    c[i]=0

for i in range(n):
  l[i]=str(l[i])
a = " ".join(l)
print(a)

Submission status: Time Limit Exceeded

Solution code:
import collections

n, K = map(int, input().split())
a = [int(i) for i in input().split()]

for k in range(K):
    change_list = []
    for i in range(n):
        #d = a[i]
        change = [j for j in range(1,n+1) if i-a[i]+0.5 < j < i+a[i]+1.5]
        change_list.extend(change)
    counter = collections.Counter(change_list)
    for m in range(n):
        a[m] = counter[m+1]

ans_list = [str(c) for c in a]
ans=' '.join(ans_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C
N,K = map(int, input().split())
lights = list(map(int, input().split()))
bright = [0 for i in range(N)]
#Kがある程度大きい場合、すべての項がNになるので、以下の動作を省く
count = 0
for light in lights:
    if light > 0:
        count+=1
if (count*(N-min(lights))<=K):
    lights = [N for y in range(N)]
#print(lights)
#print(bright)
else:
    for kaisuu in range(K):
    #すべての電球の明るさがNになったら終わる
        if sum(lights) == N**2:
            break
        for i in range(N):
        #左の電球から順に、その電球が照らす範囲のbrightに+1
            count = lights[i]
            for j in range(i-count,i+count+1):
                if 0<=j<=N-1:
                    bright[j]+=1
        lights = bright
        bright = [0 for z in range(N)]
        #print(kaisuu,lights)
        #print(kaisuu,bright)
    #print(lights)
for ans in lights:
    print(ans, end=" ")

Submission status: Time Limit Exceeded

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

dic = {}
base_dic = {}

for i, j in enumerate(A, 1):
    dic[i] = j
    base_dic[i] = 0

for l in range(K):

    dic_copy = dic.copy()
    dic = base_dic.copy()

    for i, j in dic_copy.items():
        if i - j >= 1:
            low = i - j
        else:
            low = 1
        if i + j <= N:
            high = i + j
        else:
            high = N
        for k in range(low, high + 1):
                dic[k] += 1

ans = []
for v in dic.values():
    ans.append(v)
ans = map(str, ans)
ans = " ".join(ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict

n,k=map(int,input().split())
l=list(map(int,input().split()))

for i in range(k):
	d=defaultdict(lambda:1)
	for j in range(n):
		
		for k in range(1,l[j]+1):
			if(j+k==n):
				break
			
			d[j+k]+=1
		for k in range(1,l[j]+1):
			if(j-k==-1):
				break
			d[j-k]+=1
		
	
	for j in range(n):
		l[j]=d[j]
for i in l:
	print(i,end=" ")

Submission status: Time Limit Exceeded

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

def r(i,A):
    x1=math.ceil(i+1-A[i]-0.5)
    x2=i+1+A[i]+0.5
    X=[]
    for l in range(x1,int(x2)+1):
        if(l>0):
            X.append(l)
    return X

for k in range(K):
    B=[0]*N
    for i in range(N):
        for m in r(i,A):
            n=m-1
            if(n<N):
                B[n]+=1
    A=B
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

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

A_list = [0]+list(map(int, input().split()))
A_np=np.array(A_list)
#print(A_np)

for j in range(K):
  new_A_np=np.array([0]*(N+1))
  for i in range(1,N+1):
    tmp_np=np.array([0]*(N+1))
    #print(A_np)
    mi=i-A_np[i]
    ma=i+A_np[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #print(mi,ma)
    tmp_np[mi:ma+1]=1
    #print(tmp_np)
    new_A_np+=tmp_np
  #print(new_A_np)
  A_np=new_A_np.copy()

for i in range(1,N+1):
  print(A_np[i],end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline


def light(As,N):
    A0 = np.array([0] * N)
    for i in range(N):
        lp = As[i]
        lmin = max(0, i - lp)
        lmax = min(N - 1, i + lp)
        A0[lmin:lmax + 1] += 1
    return A0

def main():
    """"ここに今までのコード"""
    N,K = map(int, input().split())
    As = np.array(list(map(int, input().split())))

    for i in range(K):
        As = light(As, N)

    print(*As,sep=" ")




if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
count = K
while count > 0:
  B = [0]*N
  for i in range(N):
    if N-1-i < A[i]:
      b = N-1
    else:
      b = i+A[i]
    if i < A[i]:
      a = 0 
    else:
      a = i-A[i]
    c = list(range(a,b+1))
    for j in range(len(c)):
      B[c[j]] += 1
  else:
    count -= 1
    A = B
print(*B)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, k = map(int, input().split())
A = [int(i) for i in input().split()]

ans = np.array([0]*n)
for i in range(k):
  ans = np.array([0]*n)
  if i == 0:
    prev = A    
  #print("prev", prev)
  for j in range(n):
      start = max(0, j - prev[j])
      end = min(n-1, j + prev[j])
      #print("start, end", start, end)
      #print(ans[start:end+1])
      ans[start:end+1] += 1
  #print(i, ans)
  prev = ans
  if all([a >= n for a in ans]):
    #print("break", ans)
    break
print(' '.join([str(a) for a in ans.tolist()]))

Submission status: Time Limit Exceeded

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

for n in range(K):
  B=[0]*N
  for i in range(N):
    key=max(0,i-A[i])
    Key=min(N,i+A[i]+1)
    for x in range(key,Key):
      B[x]+=1
      if B[x]>N:
        B[x]==N
  A=list(B)
  if B[0]==N and len(B)==1:
    break
B=[str(b) for b in B]
print(' '.join(B))

Submission status: Time Limit Exceeded

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

for turn in range(min(n, k)):
    status = [0] * n
    for x in range(n):
        for y in range(n): 
            # if x + 1 - a[x] - 0.5 < y + 1 and y + 1 < x + 1 + a[x] + 0.5:
            # if (-1) * a[x] <= x - y <= a[x]:
            if abs(x - y) <= a[x]:
                status[y] += 1
    a = status
print(' '.join(str(n) for n in a))

Submission status: Time Limit Exceeded

Solution code:
def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    # number = 635
    # dists = [1] * number
    # operations = number
    satulation = any((
        operations >= 40,
        number <= 3000 and operations >= 25,
        number <= 1000 and operations >= 21,
        number <= 625 and operations >= 20,
    ))
    if satulation:
        print(*([number] * number))
        return

    for xx in range(operations):
        dists_new = [0] * number
        min_d = number
        for i, d in enumerate(dists):
            min_d = min(d, min_d)
            start = max(0, i - d)
            end = min(i + d, number - 1)
            for j in range(start, end + 1):
                dists_new[j] += 1
        dists = dists_new
        if min_d == number:
            # すべての光が両端まで届く，変化しなくなる。
            # print('Over', xx)
            break

    print(*dists)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
tmp = input().split(' ')
A = []
for i in range(N):
    A = A + [int(tmp[i])]

Z = np.array([[abs(j - i) for j in range(N)] for i in range(N)])

B = [0]*5
while K > 0:
    K = K - 1
    Ac = np.array([A]*N-Z)
    for i in range(N):
        B[i] = np.count_nonzero(Ac[i] >= 0)

    A[:] = B[:]

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

Submission status: Time Limit Exceeded

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

for _ in range(K):
    b = [0] * N
    for i in range(N):
        start = max(i-a[i], 0)
        end = min(i+a[i]+1, N)        
        for j in range(start, end):
            b[j] += 1
    a = b

print(" ".join([str(i) for i in a]))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(k):
        dp = [0] * (n + 1)
        for index, i in enumerate(a):
            dp[max(0, index - i)] += 1
            dp[min(n, index + i + 1)] -= 1
        a[0] = dp[0]
        for i in range(1, n):
            a[i] = a[i - 1] + dp[i]
    print(*a)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

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

for i in range(K):
    addition = np.zeros(N)

    for j in range(N):
        for k in range(max(0, j - As[j]), min(N, j + As[j]+1)):
            addition[k] += 1
    As = addition.astype('int32')

print(' '.join(As.astype('str')))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, k = map(int, input().split())
a_list = np.array(list(map(int, input().split())))

for ki in range(k):
  b_list = np.array([0] * n)
  i = 0
  for ai in a_list:
    num1 = max(0,i-ai)
    num3 = max(0,n-(i+1+ai))
    num2 = n - num1 - num3
    b_list += np.array([0]*num1 + [1]*num2 + [0]*num3)
    i += 1
  a_list = b_list

print(*a_list)

Submission status: Time Limit Exceeded

Solution code:
import copy
n,k,*A = map(int,open(0).read().split())

A_1 = copy.deepcopy(A)
A_2 = copy.deepcopy(A)
for _ in range(k):
    A_1_1 = copy.deepcopy(A)
    if _ == 0:A = [0] * n
    for i,d in enumerate(A_1):
        for j in range(i-d,i+d+1):
            if 0<=j<n:
                if _ != 0 and i-A_2[i]<=j<=i+A_2[i]:continue
                A[j] += 1
    A_2 = copy.deepcopy(A_1); A_1 = copy.deepcopy(A)
    up = True
    for c in A:
        if c != n:
            up = False          
    if up:
        break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
li_light = list(map(int, input().split()))
 
def func(tuyosa):
  basho = [0] * n
  # 光が当たっている部分
  for i in range(n):
    min = i + 1 - tuyosa[i]
    max = i + 1 + tuyosa[i]
    add_list = []
    a = 0
    while a <= n:
      if 1 <= min <= n:
        basho[min - 1] += 1
      min += 1
      if min > max:
        break
  return basho
 
for i in range(k):
  li_light = (func(li_light))
 
for k in li_light:
  print(k, end=" ")

Submission status: Time Limit Exceeded

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

# if min(A[0],A[-1])+k
for _ in range(k):
    # finish=True
    start=[0]*n
    end=[0]*n
    
    for i in range(n):
        start[max(0,i-A[i])]+=1
        end[min(n-1,i+A[i])]+=1
    if start[0]==n:
        break
    # update ans
    cnt=0
    for i in range(n):
        cnt+=start[i]
        A[i]=cnt
        cnt-=end[i]

print(*A)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
num=0
ans=[0]*n
def abs_1(num1):
    return(abs(num1))
for i in range(k):
    ans=[0]*n
    for j in range(n):
        for l in range(n):
            if abs_1(j-l)<=a[l]:
                ans[j]+=1
    a=ans
    if sum(a)==n**2:
        break
print(*a)

Submission status: Time Limit Exceeded

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

tmp = [N for _ in range(N)]
for _ in range(K):
    answer = [0 for _ in range(N)]
    for i in range(N):
        minus_area = (i + 1) - A[i] - 0.5
        plus_area = (i + 1) + A[i] + 0.5
        if minus_area < 0.5:
            minus_area = 0.5
        if plus_area > N + 0.5:
            plus_area = N + 0.5
        minus_area += 0.5
        plus_area -= 0.5
        for index in range(int(minus_area) - 1, int(plus_area)):
            answer[index] += 1
    if answer == tmp:
        break
    A = answer

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

Submission status: Time Limit Exceeded

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

L = list(map(int,input().split()))

for _ in range(K):
    L_ans = [0]*N

    for i in range(N):
        dis1 = i + L[i]
        dis2 = i - L[i]
        if dis2 > 0:
            if dis1 < N:
                for j in range(dis2,dis1+1):
                    L_ans[j] += 1
            else:
                for j in range(dis2,N):
                    L_ans[j] += 1
        else:
            if dis1< N:
                for j in range(0,dis1+1):
                    L_ans[j] += 1
            else:
                for j in range(0,N):
                    L_ans[j] += 1
    L = L_ans
 
print(*L)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

n, k = map(int, input().split())
intensity = list(map(int, stdin.readline().split()))

count = 0
while count < k:
    totsum = 0
    prefs = [0]*n
    zeros = []
    for i in range(n):
        if intensity[i]!=0:
            l = i - intensity[i]
            r = i + intensity[i] + 1

            prefs[max(l, 0)] += 1
            if r <= n-1: 
                prefs[r] += -1
        else:
            zeros.append(i)
            
    for i in range(1, n):
        prefs[i] += prefs[i-1]
        totsum += prefs[i]
    
    for i in zeros:
        if intensity[i] == 0:
            prefs[i] += 1
            totsum += 1
    
    if totsum == n*k:
        print(*prefs)
        exit()
    
    intensity = prefs
    count += 1

print(*prefs)

Submission status: Time Limit Exceeded

Solution code:
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):
    for u in range(max(0,j-a[j]),min(j+a[j]+1,n)):
      b[u]+=1  
  if b==[n]*n:
    for _ in range(n):
      print(n,end=' ')
    exit()
  else:
    a=b
print(' '.join(map(str,a)))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
def inbox(i, n):
    i = max(0, i)
    i = min(i, n)
    return(i)

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    a_new = [0 for _ in range(n)]
    for i in range(n):
        left = max(i-a[i], 0)
        right = min(i+a[i]+1, n)
        for j in range(left, right):
            a_new[j] += 1
    b = [a_new[i] - a[i] for i in range(n)]

    for _ in range(k-1):
        a_old = a[:]
        a = a_new[:]
        b_new = [0 for p in range(n)]
        for i in range(n):
            ll = inbox(i - a_old[i] - b[i], n)
            lr = inbox(i - a_old[i], n)
            rl = inbox(i + a_old[i] + 1, n)
            rr = inbox(i + a_old[i] + b[i] + 1, n)
            for j in range(ll, lr):
                a_new[j] += 1
                b_new[j] += 1
            for j in range(rl, rr):
                a_new[j] += 1
                b_new[j] += 1
        b = b_new[:]


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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from copy import copy

n, k = map(int, input().split())
l = list(map(int, input().split()))
for i in range(k):
    r = [0]*n
    for j in range(n):
        if l[j] == 0:
            r[j] += 1
        else:
            for m in range(l[j], -1*l[j]-1, -1):
                if m == 0:
                    r[j+m] += 1
                else:
                    if 0 < m and j+m <= n-1:
                        r[j+m] += 1
                    elif m < 0 and 0 <= j+m:
                        r[j+m] += 1
    l = copy(r)
    if sum(r) == n**2:
        break

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

Submission status: Time Limit Exceeded

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

#print([0] *n)

for _ in range(k):
    if an == [n] *n:
        print(*an)
        exit(0)
    bn = [0] *n
    for i in range(n):
        for j in range(max(i-an[i],0), min(n, i+an[i]+1)):
            bn[j] += 1
            #print(bn)
    an = bn

print(*an)

Submission status: Time Limit Exceeded

Solution code:
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
counter=[0]*N
def count(hani,hani2):
    for j in range(hani,hani2+1):
            counter[j]+=1
for _ in range(K):
    counter=[0]*N
    for i in range(N):
        hani=int(i-A[i])
        if hani<0:hani=0
        hani2=int(i+A[i])
        if hani2>=N:hani2=N-1
        count(hani,hani2)
    A=counter.copy()
print(*counter)

Submission status: Time Limit Exceeded

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


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

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

    ans = ' '.join(list(map(str, A)))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(k):
        nxt = [1]*n
        for j in range(len(a)):
            if a[j] == 0:
                continue
            r = min(j + a[j], n-1) #look right
            l = max(j-a[j], 0) #look left
            for m in range(j+1, r+1):
                nxt[m] = min(nxt[m]+1,n)

            for m in range(l, j):
                nxt[m] = min(nxt[m]+1,n)


        a, nxt = nxt, a
        if a == nxt:
            break
    print(*a)

resolve()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
keep = a
for i in range(k):
    b = [0] * n
    for j in range(n):
        b[max(0, j - a[j]):min(n, j + a[j] + 1)] = map(lambda x: x + 1, b[max(0, j - a[j]):min(n, j + a[j] + 1)])
    a = b
    if keep == a:
        print(' '.join([str(_) for _ in a]))
        break
    else:
        keep = a
print(' '.join([str(_) for _ in a]))

Submission status: Time Limit Exceeded

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

if (N // 80)* 2 + 15 < K:
    A= [N]*N
else:
    for _ in range(K):
        B = [0] * N
        for i in range(N):
            if A[i] >= 0:
                if (A[i] >= max(N - i, i)):
                    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 = copy.copy(B)

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

Submission status: Time Limit Exceeded

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

A = list(map(int, input().split()))



for _ in range(K):
    
    A_hat = [0] * N
    # A = A_hat
   
    
    for i in range(N):
        count = 0
        for j in range(N):
            
            l = abs(i - j)
            if l <= A[j]:
                count += 1
    
        A_hat[i] = count
    # print(A_hat)
    A = A_hat
L=[str(a) for a in A_hat]
L=' '.join(L)
print(L)

Submission status: Time Limit Exceeded

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

import heapq  # heapqライブラリのimport
#heapq.heapify(a)  # リストを優先度付きキューへ
#heapq.heappop(a)  # 最小値の取り出し
    #heapq.heappush(a, -2)

for unko in range(k):

    denkyu=[]
    heapq.heapify(denkyu)
    cnt=0
    ans=[0]*n
    #print("start",a)
    for i,aa in  enumerate(a):
        if cnt==0:
            ans[i]+=1
            if aa>0:
                cnt+=1
                heapq.heappush(denkyu,i+aa+1)
        else:
            while 1:
                tmp=heapq.heappop(denkyu)
                if i<tmp:
                    heapq.heappush(denkyu, tmp)
                    break
                else:
                    cnt-=1
                if cnt==0:
                    break


            
            ans[i]+=cnt+1
            
            if aa>0:
                cnt+=1
                heapq.heappush(denkyu,i+aa+1)
        #print(aa,denkyu)
    #print(unko,ans,a)

    aaa=a[::-1]
    denkyu2=[]
    heapq.heapify(denkyu2)
    cnt2=0
    ans2=[0]*n
    for i,aa in  enumerate(aaa):
        if cnt2==0:
            if aa>0:
                cnt2+=1
                heapq.heappush(denkyu2,i+aa+1)
        else:
            while 1:
                tmp=heapq.heappop(denkyu2)
                if i<tmp:
                    heapq.heappush(denkyu2, tmp)
                    break
                else:
                    cnt2-=1
                if cnt2==0:
                    break


            
            ans2[i]+=cnt2
            if aa>0:
                cnt2+=1
                heapq.heappush(denkyu2,i+aa+1)

    ans2=ans2[::-1]

    flag=0
    for i,v in enumerate(ans2):
        a[i]=v+ans[i]
        if a[i]!=n:
            flag=1

    if flag==0:
        break
    #print(unko,a)


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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

n, k = map(int, input().split())
intensity = list(map(int, stdin.readline().split()))

count = 0
while count < k:
    totsum = 0
    prefs = [0]*n
    for i in range(n):
        if intensity[i]!=0:
            l = i - intensity[i]
            r = i + intensity[i] + 1

            prefs[max(l, 0)] += 1
            if r <= n-1: 
                prefs[r] += -1

    for i in range(1, n):
        prefs[i] += prefs[i-1]
        totsum += prefs[i]
    
    for i in range(n):
        if intensity[i] == 0:
            prefs[i] += 1
            totsum += 1
    
    if totsum == n*k:
        print(*prefs)
        exit()
    
    intensity = prefs
    count += 1

print(*prefs)

Submission status: Time Limit Exceeded

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

if k >= n:
    for i in range(n-1):
        print(n, end=" ")
    print(n)
    exit()

for _ in range(k):
    list = [1]*n
    for i, d in enumerate(a):
        if d == 0:
            continue
        for j in range(-d, d+1):
            if j == 0:
                continue
            if i+j >= 0:
                try:
                    list[i+j] += 1
                    # print(i, j)
                except:
                    pass
    a = list.copy()
for i in range(n-1):
    print(a[i], end=" ")
print(a[-1])

Submission status: Time Limit Exceeded

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

import sys
import math

if K > 3.5962*math.log(N):
    A = [N]*N
    print(' '.join(map(str, A)))
    sys.exit()
    

lenA = len(A)
for i in range(K):
    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)] = [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(i+1)
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

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

for i in range(k):
  for j in range(n):
    for m in range(n):
      if a[m] >= abs(m-j):
        b[j] += 1
  a = b  
  b = [0]*n
print(*a)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = [1 for _ in range(N)]
for i in range(K):
    for j in range(N):
        for k in range(j-A[j],j+A[j]+1):
            if 0 <= k < N and k != j:
                L[k] += 1
    A = L
    L = [1 for _ in range(N)]
print(*A)