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:
# coding: utf-8
#import numpy as np
import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import bisect
from queue import PriorityQueue
import itertools
from copy import deepcopy
import random
import time
import os
import sys
import datetime
from functools import lru_cache
from functools import reduce
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
alphabet="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):
    if b:print("yes")
    else:print("no")
def Yn(b):
    if b:print("Yes")
    else:print("No")
def YN(b):
    if b:print("YES")
    else:print("NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(bbool,ret1,ret2):
    if bbool:return ret1
    else:return  ret2
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def pm(x):
    return x//abs(x)
def inputintlist(): 
    return list(map(int,input().split()))
def inputfloatlist(): 
    return list(map(float,input().split()))
def tozero(A):
    ret=[None]*len(A)
    for a in range(len(A)):
        ret[a]=A[a]-1
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])#[cost,x]
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def ruisekiwa(A):
    ret=[0]*(len(A)+1)
    for a in range(len(A)):
        ret[a+1]=ret[a]+A[a]
    return ret
def getmd(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def heron(a,b,c):
    s=(a+b+c)/2
    S=s(s-a)(s-b)(a-c)
    S=math.sqrt(S)
    return S
def getAreaOfTriangle(x1,y1,x2,y2,x3,y3):
    a=geted(x1,y1,x2,y2)
    b=geted(x2,y2,x3,y3)
    c=geted(x3,y3,x1,y1)
    return heron(a,b,c)






######################################################################################################



N,K=inputintlist()
A=inputintlist()
for k in range(min(100,K)):
    imos=[0]*(N+1)
    for a in range(len(A)):
        mmin=max(a-A[a],0)
        mmax=min(a+A[a],N-1)
        imos[mmin]+=1
        imos[mmax+1]-=1
    B=[0]*N
    B[0]=imos[0]
    for a in range(1,N):
        B[a]=imos[a]+B[a-1]
    A=B[:]
print(join(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):
        B[i] += 1
        if A[i] > 0:
            if (A[i] > N - 1):
                B = list(map(lambda x: x+1, B))
            else:
                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: Time Limit Exceeded

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

for z in range(K):
  #print("############### ",z,"回目 #############")
  A_range = list() #照らしてる範囲のリスト
  for i in range(1,len(A)+1):
    i_range = list() #i番目のライトが照らす範囲
    light = A[i-1]
    i_range = [i - light - 0.5,i + light + 0.5]
    A_range.append(i_range)
  #print(A_range)
  i_count = [0]*len(A) #座標iを照らすライトの数
  for i in range(1,len(A)+1):
    #print("i:",i)
    for j in range(len(A)):
      #print(A_range[j])
      if A_range[j][0] <= i and A_range[j][1] >= i:
        i_count[i-1] += 1
    A[i-1] = i_count[i-1]
for i in range(len(A)):
  print(A[i], end=' ')

Submission status: Time Limit Exceeded

Solution code:
from copy import copy
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):
        d = a[j]
        for l in range(max(0,j-d),min(n,j+d+1)):
            b[l] += 1
        
    a = copy(b)

a = [str(x) for x in a]
print(' '.join(a))

Submission status: Time Limit Exceeded

Solution code:
N , K = (int(a) for a in input().split())
A = list(map(int, input().split()))
B = [0]*N

while K > 0 :
    for i in range (N) :
        c = A[i]
        while c >= 0 :
            if i + c < N and c != 0 :
                B[i+c] += 1
            if i - c >= 0 and c != 0 :
                B[i-c] += 1 
            if c == 0 :
                B[i] += 1
            c -= 1
    A = B
    B = [0]*N
    K -= 1
    if A == [N]*N :
        break

print(*A)

Submission status: Time Limit Exceeded

Solution code:
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]

#k回ループ
for _ in range(k):
    b=[0 for x in range(n)]
    for i in range(n):
       d=a[i]
       left=max(0,i-d)
       right=min(n-1,i+d)
       for j in range(left,right+1):
           b[j]+=1
    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()))


class BIT:
    def __init__(self, n):
        self.n = n
        self.N = 1 << n.bit_length()
        self.data = [0] * (self.N +1)

    def add(self, i, x):
        while i <= self.N:
            self.data[i] += x
            i += i & -i

    def sum(self, i):
        total = 0
        while i > 0:
            total += self.data[i]
            i -= i&-i
        return total

    def search(self, w):
        if w <= 0:
            return 0
        x = 0
        k = self.N >> 1
        while k > 0:
            if x+k <= self.N and self.data[x+k] < w:
                w -= self.data[x+k]
                x += k
            k = k >> 1
        return x+1

    def len(self):
        return self.data[self.N]

list1 = BIT(n+1)
for i in range(n):
    list1.add(max(i-a[i]+1, 1), 1)
    list1.add(min(n+1, i+a[i]+2), -1)

for _ in range(k-1):
    nex = BIT(n+1)
    maxc = 0
    for i in range(1, n+1):
        bt = list1.sum(i)
        nex.add(max(1, i-bt), 1)
        nex.add(min(n+1, i+bt+1), -1)
        if bt == n:
            maxc += 1
    list1 = nex
    if maxc == n:
        break

res = []
for i in range(1, n+1):
    res.append(list1.sum(i))
print(' '.join(map(str, res)))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from sys import setrecursionlimit
import numpy as np

setrecursionlimit(10 ** 7)

n,k = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
a = np.array(a,dtype=np.int64)
lamp= np.zeros(n,dtype=np.int64)

for i,j in enumerate(a):
    lamp[max(0,i-j):min(n+1,i+j+1)] += 1

if k == 1:
    print(*lamp)
    exit()

for _ in range(min(k-1,17)):
    b = np.zeros(n,dtype=np.int64)
    for i,j in enumerate(lamp):
        b[max(0,i-j):min(n+1,i+j+1)] += 1
    b[b>n] = n
    lamp = b.copy()

lamp[lamp>n] = n

print(*lamp)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, A: "List[int]"):
    for i in range(K):
        B = [int()] * (N)
        for j in range(N):
            B[j] +=1
            for k in range(1, A[j]+1):
                if j-k >= 0:
                    B[j-k] +=1
                if j+k < N:
                    B[j+k] +=1
        A = B
    A=[str(a) for a in A]
    A=' '.join(A)
    print(A)
    return 0

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
    solve(N, K, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n, k, *a = map(int, read().split())

for _ in range(k):
    b = [0] * n
    for i in range(n):
        d = a[i]
        for j in range(i-d, i+d+1):
            if j < 0 or j >= n:
                continue
            b[j] += 1
    
    a = b

print(*[b[i] for i in range(n)])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
A = list( map(int, input().split()))

light_intensity = A

for k in range(K):
    new_light_intensity = [0 for i in range(N)]
    for i in range(N):
        for l in range(max(0,i-light_intensity[i]), min(i+light_intensity[i]+1, N)):
            new_light_intensity[l] += 1

    light_intensity = new_light_intensity
    if set(light_intensity) == set([N]):
        print(" ".join(map(str, light_intensity)))
        exit(0)

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
tenjo = n
a = list(map(int, input().split()))
for j in range(k):
  b = [0]*n
  for i in range(n):
    if max(0, i-a[i]) + min(n, i+a[i]+1) >= n:
      tenjo -= 1
    for e in range(max(0, i-a[i]), min(n, i+a[i]+1)):
      b[e] += 1
  a = b
  if a.count(tenjo) == n:
    break
print(" ".join(list(map(str, a))))

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
for i in range(K):
    CA = [A[i] for i in range(N)]
    for j in range(N):
        if A[j] == N:
            continue
        else:
            cnt = 1
            for k in range(N):
                if j == k:
                    continue
                elif CA[k] >= abs(k-j):
                    cnt += 1
            A[j] = cnt
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def p():
  n,k = map(int,input().split())
  x =n**2
  a = list(map(int,input().split()))
  for _  in range(k):
    s = 0
    newa = [0 for _ in range(n)]
    for i in range(n):
      d = a[i]
      s += min(n-1,i+d)+1-max(0,i-d)
      for j in range(max(0,i-d),min(n-1,i+d)+1):
        newa[j] += 1
    a = newa
    if s == x:
      break
  for ai in a:
    print(ai,end=" ")
p()

Submission status: Time Limit Exceeded

Solution code:
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 (max(0, i - A[i]), min(i + A[i] + 1, N)):
            B[j] += 1
    A = B

print(*B)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
tmp = [0] * N
count = 0

for t in range(K):
    for i in range(N):  # i番目の電球の明るさを決定する
        if A[i] == N:
            tmp[i] = N
        else:
            for j in range(N):  # 各電球jが、電球iを照らしているかを確認する
                if j - A[j] - 0.5 <= i <= j + A[j] + 0.5:
                    count += 1
            tmp[i] = count
        count = 0
    for l in range(N):
        A[l] = tmp[l]

print(*A)

Submission status: Time Limit Exceeded

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

for i in range(k):
    nn = 3*n
    b = [0] * nn;

    for p in range(n):
        for q in range(p-a[p],p+a[p]+1):
            b[q + n] += 1;
        
    for v in range(n):
        a[v] = b[v+n];

L = [str(f) for f in a];
L = " ".join(L);
print(L);

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 k in range(n):
      if a[k] >= abs(k-j):
        b[j] += 1
  a = b  
  b = [0]*n
  if a[0] == n:
    count += 1
  if count ==2 :
    break

print(*a)

Submission status: Time Limit Exceeded

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

def light_distance(x,power):
  return [x-power-0.5,x+power+0.5]

def light_power_position(power_range):
  start = power_range[0]
  end = power_range[1]
  return [1 if i>=start and end>=i else 0 for i in range(1,n+1)]

max_power = [n for i in range(n)]
for i in range(k):
  number_light = [0 for i in range(n)]
  for j in range(1,n+1):
    number_light = list(map(sum, zip(number_light, light_power_position(light_distance(j,light_power[j-1])))))
  light_power = number_light
  if light_power == max_power:
    break
print(' '.join(map(str, light_power)))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = map(int,input().split())
a = list(map(int,input().split()))
res = [val for val in a]
for k in range(K):
    delta = [0]*(N+1)
    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 = list(np.cumsum(delta, dtype=np.int32))[:N]
    if sum(res) == N**2:
        break
print(*res)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())	
A = list(map(int,input().split()))
B = [0]*N
for _ in range(K):
    for i in range(len(A)):
        if i-A[i] >= 0 and i+A[i]+1 <= N:
            for j in range (i-A[i],i+A[i]+1):
                B[j] += 1
        elif i-A[i] < 0 and i+A[i]+1 <= N:
            for j in range(0,i+A[i]+1):
                B[j] += 1
        elif i-A[i] >= 0 and i+A[i]+1 > N:
            for j in range(i-A[i],N):
                B[j] += 1
        else:
            for j in range(N):
                B[j] +=1
    A = B[:]
    B = [0]*N
ans = ' '.join(map(str,A))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
n,k = map(int,input().split())

L = list(map(int,input().split()))
#Lt = copy.copy(L)

for i in range(k):
    Lt = [0 for i in range(n)]
    for j in range(n):
        
        if L[j] > 0:
            for m in range(1,L[j]+1):
                if j-m>=0:
                    Lt[j-m] += 1
                if j+m<=n-1:
                    Lt[j+m] += 1
        Lt[j] += 1
        #print(Lt)
    L = copy.copy(Lt)

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

Submission status: Time Limit Exceeded

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, K = rl()
A = rl()

class BIT:
    def __init__(self, n):
        self.nums = [0] * (n+1)
        
    def add(self, i, x):
        i += 1
        while i < len(self.nums):
            self.nums[i] += x
            i += i & -i
    
    def sum(self, i):
        s = 0
        i += 1
        while i:
            s += self.nums[i]
            i -= i & -i
        return s

for k in range(K):
    bit = BIT(N+1)
    for i in range(N):
        I = max(0, i-A[i])
        J = min(N, i+A[i]+1)
        bit.add(I,1)
        bit.add(J,-1)
    flag = True
    for i in range(N):
        A[i] = bit.sum(i)
        if A[i] < N:
            flag = False
    if flag: break
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 for a in A]

i = 0

while K > 0:
    for i in range(N):
        for j in range(1, A[i]+1):
            if i - j >= 0:
                B[i-j] += 1
            if i + j < N:
                B[i+j] += 1
        B[i] += 1
    A = [b for b in B]
    B = [0 for a in A]
    K -= 1

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A_list = [int(n) for n in input().split()]

for k in range(K):

    B_list = list()
    R_list = list()

    for m in range(N):
        inf = m + 1 - A_list[m] - 0.5
        sup = m + 1 + A_list[m] + 0.5
    
        inf_int = int(np.ceil(inf))
        sup_int = int(np.floor(sup))
    
        R_list = R_list + list(range(inf_int, sup_int + 1))
    
    
    for m_2 in range(N):    
        B_list.append(R_list.count(m_2 + 1))
    
        A_list = B_list.copy()
        
print(' '.join(map(str, A_list)))

Submission status: Time Limit Exceeded

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)
    B=np.cumsum(B)[:N]
    if B.min()==N:
        break
    #print(B)
    A=B.copy()
    
print(*B)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
if K >= N:
    print(" ".join([str(N)]*N))
else:
    for _ in range(K):
        B = [1]*N
        for i in range(N):
            for j in range(1, A[i]+1):
                if i-j >= 0:
                    B[i-j] += 1
                if i+j < N:
                    B[i+j] += 1
        if A == B:
            break
        A = B

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int,input().split())
A = list(map(int,input().split()))
K = min(41,K)
#A = [0] * N

for k in range(K):
    imos = [0] * (N+1)
    for n in range(N):
        a = n - A[n]
        b = n + A[n]
        a = max(0,a)
        b = min(N-1,b)
        imos[a] += 1
        imos[b+1] -= 1
    csum = list(itertools.accumulate(imos))
    A = csum[:-1]
A = [str(a) for a in A]
print (' '.join(A))

Submission status: Time Limit Exceeded

Solution code:
import math


N,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
Atemp=[0 for i in range(len(A))]
#print(Atemp)
flag=1
for i in range(K):
    for j in range(1,len(A)):
        start=max(1,j-A[j])
        end=min(len(A),j+A[j]+1)
        for k in range(start,end):
            Atemp[k]+=1
    """
    for l in range(1,int(len(A)/2)):

        if Atemp[l]>abs(len(A)-l):
            flag*=1
        else:
            flag*=0

    for l in range(int(len(A)/2),len(A)):
        if Atemp[l]>l:
            flag*=1
        else:
            flag*=0

    """

    A=Atemp.copy()
    Atemp = [0 for i in range(len(A))]
    """
    if flag==1:
        for o in range(1,len(A)):
            A[o]+=(K-i+1)*len(A)
            print(o)
        break
    flag=1
    """
for m in range(1,len(A)):
    print(A[m],end=" ")

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(k):
  add_a=[0]*(n+1)
  for i in range(n):
    a[i]
    add_a[max(0,i-a[i])]+=1
    add_a[min(n,i+a[i]+1)]-=1
  tmp=0
  for i in range(n):
    tmp+=add_a[i]
    a[i]=tmp
print(' '.join(map(str,a)))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
tu=0
td=0
for j in range(k):
  temp=[0]*n
  for i in range(n):
    td=max(i+1-a[i],1)
    tu=min(i+1+a[i],n)
    for m in range(td-1,tu):
      temp[m]=temp[m]+1
  a=temp
  if sum(a)==n**2:
    break
L=[str(t) for t in a]
L=" ".join(L)
print(L)

Submission status: Time Limit Exceeded

Solution code:
import copy
n, k = (int(i) for i in input().split(' '))
a = [int(i) for i in input().split(' ')]

for i in range(k):
    c = copy.copy(a)
    for j in range(1, n + 1):
        b = 0
        for l in range(1, n + 1):
            if j == l:
                b += 1
            elif j < l and l - c[l - 1] - 0.5 <= j:
                b += 1
            elif j > l and l + c[l - 1] + 0.5 >= j:
                b += 1
        a[j - 1] = b
print(' '.join([str(i) for i in a]))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = input().split()#string
A = list(map(int, A))
for i in range(K):
  B = [0 for i in range(N)]
  for j in range(N):
    tmp_low = j - A[j] 
    tmp_high = j + A[j] 
    if tmp_low <= 0:
      tmp_low = 0
    if tmp_high >= N-1:
      tmp_high = N-1
    for k in range(tmp_low, tmp_high+1, 1):
      B[k] = B[k] + 1
  A = B
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import copy

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


for _ in range(K):
    T = [0]*N
    for i in range(N):
        for j in range(max(0,i-A[i]), min(N-1, i+A[i])+1):
            T[j] += 1
    A = copy.copy(T);
    
print(*A)

Submission status: Time Limit Exceeded

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

if N<=K:
    ans = [str(N)]*N
    print(' '.join(ans))
    exit()

light = [0]*N
last_light = A
for j in range(K):
    for i in range(N):
        if i-last_light[i] < 0:
            start = 0
        else:
            start = i-last_light[i]
        if i+last_light[i] > N:
            last = N
        else:
            last = i+last_light[i]
        light = light[:start] + list(map(lambda x:x+1,light[start:last+1])) + light[last+1:]
    last_light = copy.copy(light)
    light = [0]*N

for i in range(N):
    last_light[i] = str(last_light[i])
print(' '.join(last_light))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    for j in range(K):
        B = np.zeros_like(A)
        for i in range(N):
            temp = A[i]
            left = i - temp
            right = i + temp + 1
            if left < 0:
                left = 0
            if right > N:
                right = N
            B[left:right] += 1
        A = B

    print(*A)



main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int, input().split())
A = list(map(int, input().split()))
for count in range(K):
    area = []
    area = [[i2 + 1 for i2 in range(int(i + 1 - v - 0.5),int(i + 1 + v + 0.5))] for i,v in enumerate(A)]
    area = list(itertools.chain.from_iterable(area))
    newA = []
    newA = [area.count(i + 1) for i,v in enumerate(A)]
    A = newA
print(*A)