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:
import sys
input = sys.stdin.readline

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

for i in range(k):
    kari = [0] * n
    for j in range(n):
        range_j = range(max(j+1-light[j],1), min(j+2+light[j],n+1))
        for h in range_j:
            kari[h-1] += 1
    light = kari
    kari = [0] * n

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
ans=a[:]
for i in range(k):
    tmp=np.zeros(n,dtype=int)
    for i in range(n):
        tmp[max(0,i-ans[i]) : min(n,i+ans[i]+1)]+=1
    ans=tmp
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(K):
    newA = [0]*N
    for j in range(N):
        newA[max(0,j-A[j])] += 1
        if j+A[j]+1 < N:
            newA[min(N-1,j+A[j]+1)] -= 1
    A = list(itertools.accumulate(newA))
for i in range(N):
    A[i] = str(A[i])
print(' '.join(A))

Submission status: Time Limit Exceeded

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


def solve(N: int, K: int, A: "List[int]"):
    for n in range(K):
        L = [0] * N
        for i in range(N):
            for j in range(A[i]+1):
                if j!=0:
                    if i-j>=0:
                        L[i-j] += 1
                    if i+j<N:
                        L[i+j] += 1
                else:
                    L[i+j] += 1
        if A==L:
            A = L
            break
        if sum(A)==N*N:
            A = L
            break
        A = L

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


# Generated by 1.1.7.1 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(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
n , k = map(int, input().split())
a = list(map(int,input().split()))
a1=[0]*n
k = min(k,int(math.log2(n)*2.5))
for i in range(k):
    for j in range(n):
        if j-a[j]>=0:
            if j+a[j]<n:
                for k in range(j-a[j],j+a[j]+1):
                    a1[k]+=1
            else:
                for k in range(j-a[j],n):
                    a1[k]+=1
        else:
            if j+a[j]<n:
                for k in range(j+a[j]+1):
                    a1[k]+=1
            else:
                for k in range(n):
                    a1[k]+=1
    a=a1
    a1=[0]*n
print(' '.join([str(n) for n in a]))

Submission status: Time Limit Exceeded

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

def updateAi(Ai):
  newAi = [1 for _ in range(N)]
  for i in range(N):
    for j in range( max(-1*Ai[i],-1*i),min(Ai[i]+1, N-i)):
      #print('j = '+str(j))
      if(j!=0):
        
        newAi[i+j] += 1
    #print('newAi at '+str(i)+' = '+str(newAi))
  
  return newAi

for j in range(K):
  Ai = updateAi(Ai)

#print(Ai)
L=[str(Ai) for Ai in Ai]
L=" ".join(L)
print(L)

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):
    Next = [0] * N
    for i in range(N):
        for idx in range(max(0, i - A[i]), min(N, 1+ i + A[i])):
            Next[idx] += 1
    A = Next
print(*Next)

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)
    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)
#    print([a == b for a, b in zip(A,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: Time Limit Exceeded

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

for k in range(K):
    tmp = [0] * N
    for i in range(1, N+1):
        for j in range(i-A[i-1]-1, i+A[i-1]):
            if 0 <= j < N:
                tmp[j] += 1
    for i in range(N):
        A = tmp

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
def LI():return list(map(int,input().split()))

n,k=LI()
import numpy as np
a=np.array(LI(),dtype=np.int32)

while k>0:
    b=np.zeros(n,dtype=np.int32)
    for i in range(n):
        b[max(0,i-(a[i])):min(n-1,i+(a[i]))+1]+=1
    a=b
    k-=1
print(*a)

Submission status: Time Limit Exceeded

Solution code:
class A:

    def solve(self):
        name = input()
        print(name[:3])

class B:

    def solve(self):
        [a, v] = [int(x) for x in input().split(" ")]
        [b, w] = [int(x) for x in input().split(" ")]
        t = int(input())

        if a == 0:
            if b < 0:
                a_end = a - t * v
                b_end = b - t * w

                if a_end <= b_end:
                    print("YES")
                else:
                    print("NO")
            else:
                a_end = a + t * v
                b_end = b + t * w

                if a_end >= b_end:
                    print("YES")
                else:
                    print("NO")
        elif b == 0:
            if a > 0:
                a_end = a - t * v
                b_end = b - t * w

                if a_end <= b_end:
                    print("YES")
                else:
                    print("NO")
            else:
                a_end = a + t * v
                b_end = b + t * w

                if a_end >= b_end:
                    print("YES")
                else:
                    print("NO")
        elif a > 0 and b < 0:
            a_end = a - t * v
            b_end = b - t * w

            if a_end <= b_end:
                print("YES")
            else:
                print("NO")
        elif a < 0 and b > 0:
            a_end = a + t * v
            b_end = b + t * w

            if a_end >= b_end:
                print("YES")
            else:
                print("NO")
        elif a < 0 and b < 0:
            if a < b:
                a_end = a + t * v
                b_end = b + t * w

                if a_end >= b_end:
                    print("YES")
                else:
                    print("NO")
            else:
                a_end = a - t * v
                b_end = b - t * v

                if a_end <= b_end:
                    print("YES")
                else:
                    print("NO")
        else:
            if b > a:
                a_end = a + t * v
                b_end = b + t * w

                if a_end >= b_end:
                    print("YES")
                else:
                    print("NO")
            else:
                a_end = a - t * v
                b_end = b - t * v

                if a_end <= b_end:
                    print("YES")
                else:
                    print("NO")

class C:

    def check_same(self, l):
        for i in range(len(l) - 1):
            if l[i] != l[i + 1]:
                return False

        return True

    def solve(self):
        [n, k] = [int(x) for x in input().split(" ")]
        intensities = [int(x) for x in input().split(" ")]

        if k >= n:
            print(" ".join([str(n) for x in range(n)]))
            return

        for o in range(k):
            new_intensities = [0 for x in range(n)]

            for i in range(n):
                for e in range(max(0, i - intensities[i]), min(i + intensities[i] + 1, n)):
                    new_intensities[e] += 1

            intensities = new_intensities

            if self.check_same(new_intensities) and new_intensities[0] == n:
                break

        print(" ".join([str(x) for x in intensities]))

C().solve()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split(" "))
As = list(map(int, input().split(" ")))
assert len(As) == N

# print(As)

for k in range(K):
  reach = {}
  for i, a in enumerate(As):
    # print(f"{i}を調べる")
    for j in range(max([0, i - a]), min([N-1, i + a]) + 1):
      # print(f"{i}は強さ{a}なので{j}を照らす")
      if reach.get(j) is None:
        reach[j] = [i]
      else:
        reach[j].append(i)
    # print(f"それぞれを照らすランプ {reach}")
  for i in range(N):
    As[i] = len(reach[i])
print(" ".join(list(map(str, As))))

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N,K = isRaw()
    As = isRaw()
    for k in range(K):
        #nAs = [0]*N
        dh = []
        for aidx,a in enumerate(As):
            heappush(dh, (max(0, aidx-a),1))
            heappush(dh, (min(aidx+a+1, N),-1))
        d = 0
        for x in range(N):
            while len(dh)!=0 and x ==dh[0][0]:
                c, q = heappop(dh)
                d+=q
            As[x] = d

        
        if sum(As) == N*N:
            break
        
    print(" ".join([str(a) for a in As]))




main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')


def solve(n, k, a):
    # wia(a)
    for _ in range(k):
        b = [0] * n
        reached = 0
        for i in range(n):
            for j in range(max(0, i - a[i]), min(n, i + a[i] + 1)):
                b[j] += 1
                if b[j] == n:
                    reached += 1
        a = b
        # wia(a)
        if reached == n:
            break
    return a


def main():
    n, k = ria()
    a = ria()
    wia(solve(n, k, a))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    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):
            l = max(0,j-A[j])
            r = min(N-1,j+A[j])
            B[l:r+1] = map(lambda x:x+1, B[l:r+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):
    A = [list(itertools.chain.from_iterable([[i2 + 1 for i2 in range(int(i + 1 - v - 0.5),int(i + 1 + v + 0.5))] for i,v in enumerate(A)])).count(i + 1) for i,v in enumerate(A)]
print(*A)

Submission status: Time Limit Exceeded

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

bef = copy.copy(A)
aft = [0 for _ in range(n)]
aft_array = np.array(aft)

for k in range(K):
    for i in range(n):
        a = bef[i]
        aft_array[max(0, i-a):min(n-1, i+a)+1]+=1
    bef = aft_array.tolist()
    aft = [0 for _ in range(n)]
    aft_array = np.array(aft)
print(*bef)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=[n for i in range(n)]
for i in range(k):
    b=[0 for i in range(n)]
    for j in range(n):
        for k in range(max(j-a[j],0),min(j+a[j]+1,n)):
            b[k]+=1
    #print(b)
    a=b
    if b==c:
        break
print(*a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K=map(int, input().split())
AA=[int(i) for i in list(input().split())]
A=np.array(AA)
B=np.zeros(N).astype("i8")
for i in range(K):
  for j in range(N):
    B[max(j-A[j],0):min(j+A[j]+1,N)]+=1
  A=B
  B=np.zeros(N).astype("i8")
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()))
A=np.array(a)
l,r=0,0
for i in range(k):
    B=np.zeros(n,dtype=np.int64)
    for x,y in enumerate(list(A)):
        l=max(0,x-y)
        r=min(n-1,x+y)
        B[l:r+1]+=1
    A=B
print(*A,sep=' ')

Submission status: Time Limit Exceeded

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

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

count = 0
for j in range(k):
    b = [0]*n
    for i in range(n):
        if i-a[i]>0:
            start = i-a[i]
        else:
            start = 0
        if i+a[i]+1>n:
            end = n
        else:
            end = i+a[i]+1
        if start == 0 and end == n:
            count += 1
        else:
            for l in range(start,end):
                 b[l] += 1
    a = b

for i in range(n):
    a[i] += count
    

print(*a)

Submission status: Time Limit Exceeded

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

for _ in range(k):
    l = []
    b = [0]*n
    for i in range(1, n+1):
        x = i-a[i-1]-0.5
        y = i+a[i-1]+0.5
        l.append([x, y])
    for j in range(1, n+1):
        for x, y in l:
            if x <= j <= y:
                b[j-1] += 1
    a = b
print(' '.join(map(str, b)))

Submission status: Time Limit Exceeded

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

for c in range(200):
    if(c == k): break
    tmp = [0 for _ in range(n)]
    for i in range(n):
        l = max(i - a[i], 0)
        r = min(i + a[i], n-1)
        
        for j in range(l, r+1):
            tmp[j] += 1
    for j in range(n):
        a[j] = tmp[j]

print(*a)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    finish = [False] * N
    for i in range(K):
        start = [0] * N
        end = [0] * N
        for j in range(N):
            if j - A[j] < 0:
                start[0] += 1
            else:
                start[j-A[j]] += 1
            if j + A[j] >= N:
                pass
            else:
                end[j+A[j]] += 1
        tmp = start[0]
        A[0] = tmp
        for j in range(1, N):
            tmp += start[j]
            tmp -= end[j-1]
            A[j] = tmp
            if tmp >= N:
                finish[j] = True
        if False not in finish:
            break
    print(" ".join(map(str, A)))

if __name__ == '__main__':
    main()

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):
    b = [0] * n
    for j in range(1, n + 1):
        n1 = j - a[j - 1]
        n2 = j + a[j - 1]
        if n1 < 1:
            n1 = 1
        if n2 > n:
            n2 = n
        for l in range(n1, n2 + 1):
            b[l - 1] += 1
    a = copy.copy(b)
        
print(' '.join([str(i) for i in a]))

Submission status: Time Limit Exceeded

Solution code:
#貪欲じゃダメ？
n,k=map(int,input().split())
A=list(map(int,input().split()))
for z in range(k):
  B=[0]*n
  for i in range(n):
    d=A[i]
    for j in range(2*d+1):
      if i-d+j>=0 and i-d+j<n:
        B[i-d+j]+=1
  A=B
print(*A)

Submission status: Time Limit Exceeded

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

for _ in range(0, k):
    tmp = []
    for i in range(0, n):
        l = i - a[i] - 0.5
        r = i + a[i] + 0.5
        tmp.append([1 if l <= ii <= r else 0 for ii in range(0, n)])

    for i in range(0, n):
        a[i] = sum([c[i] for c in tmp])

ans = ' '.join([str(i) for i in a])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

d = {}


def solve(s, N):
    lamps = [int(i) for i in s.strip().split()]
    dp = [0] * N
    for idx, l in enumerate(lamps):
        for j in range(idx - l, idx + l + 1):
            if j >= 0 and j < N:
                dp[j] += 1
    d[s] = " ".join([str(i) for i in dp])
    return d[s]


def main():
    N, K = [int(i) for i in input().strip().split()]
    lamps = input().strip()

    for _ in range(K):
        if lamps not in d.keys():
            lamps = solve(lamps, N)
        else:
            lamps = d[lamps]
    return lamps


if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
*A, = map(int, input().split())
for _ in range(K):
    counter = [0] * (N+2)
    for i, a in enumerate(A, 1):
        counter[max(0, i - a)] += 1
        counter[min(N + 1, i + a + 1)] += -1
    end = True
    for i in range(1, len(counter) - 1):
        counter[i] += counter[i-1]
        if counter[i] != N: end = False
    A = counter[1:N+1]
    if end: break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
if K >= N:
    ans = [N]*N
    print(*ans)
else:
    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:
N,K=map(int,input().split())
A = list(map(int,input().split()))

l_chk=[0] * N
cnt = 0

if N <= K:
    for i in range(N):
        A[i] = N
    print(*A)
    exit()

for i in range(K):

    l_chk=[0] * N
    for j in range(N):
        min = j - A[j]
        if min < 0:
            min = 0
        max = j + A[j]
        if max >= N:
            max = N-1

        for k in range(min,max+1):
            l_chk[k] = l_chk[k] + 1

    for j in range(N):
        A[j] = l_chk[j]

print(*A)

Submission status: Time Limit Exceeded

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

    dp = [[0]*n for _ in range(k+1)]
    for i in range(n):
        dp[0][i] = A[i]

    for i in range(1,k+1):
        fin = 0
        for j in range(n):
            pwr = dp[i-1][j]
            if pwr == n:
                fin+=1
                continue
            for a in range(max(j-pwr,0),min(j+pwr+1,n)):
                dp[i][a]+=1

        if fin == n:
            break
        else:
            for j in range(n):
                dp[i][j] += fin
    
    if fin == n:
        for j in range(n-1):
            print(dp[i-1][j], end=" ")   
        print(dp[i-1][n-1])

    else:
        for j in range(n-1):
            print(dp[i][j], end=" ")
        print(dp[i][n-1])
main()

Submission status: Time Limit Exceeded

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

for i in range(K):
    Ad = [1]*N
    for j in range(N):
        for k in range(A[j]):
            if j-k-1>=0:
                Ad[j-k-1]+=1
            if j+k+1<N:
                Ad[j+k+1]+=1
    A = Ad

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

Submission status: Time Limit Exceeded

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

pre = A
for i in range(0,K,1):
    now = [0]*N
    for j in range(0,N,1):
        for k in range(max(0,j-pre[j]),min(N,j+pre[j]+1),1):
            now[k]+=1
    owari = True
    for j in range(0,N,1):
        if now[j]!=N:
            owari = False
        pre[j]=now[j]
    if owari:
        break
print(" ".join(list(map(str,now))))

Submission status: Time Limit Exceeded

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

for k in range(K):
    b = [0 for _ in range(N)]
    for i in range(N):
        for j in range(max(i-a[i], 0), min(i+a[i]+1, N)):
            b[j] += 1
    a = b
    
ans = ""
for i in range(N):
    ans += str(a[i])
    if i != N-1:
        ans += " "
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def conv(A,N):
    #A(座標iの電灯の強さリスト)からB(座標iを照らしている電灯数)への変換
    B=[0 for n in range(N)]
    for n in range(1,N+1):
        il_min=max(int(n-A[n-1]-0.5)+1,0)
        il_max=min(int(n+A[n-1]+0.5),N)
        for i in range(il_min-1,il_max):
            B[i]+=1
    return B

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

    for k in range(K):
        B=conv(A,N)
        if A==B:
            break
        else:
            A=B
    return " ".join(list(map(str,A)))

if __name__=="__main__":
    print(main())

Submission status: Time Limit Exceeded

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

l=len(A)
for _ in range(K):
    B = [0] * N
    for i in range(l):
        k=A[i]
#        print(i)
        for j in range(max(i-k,0),min(i+k+1,l)):
#            print(j, max(i-k,0),min(i+k+1,l))
            B[j]+=1
    A=B.copy()
print(" ".join(map(str,B)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

# = int(input())
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
length = len(A)
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

for i in range(K):
    count = 0
    zero = np.array([0]*N)
    for j in range(N):
        if A[j] == length:
            zero[j] = length
        else:
            count += 1
            if j + A[j] + 1 >= length:
                zero[j:] += 1
            else:
                zero[j:A[j]+j+1] += 1
            if j - A[j] - 1 < 0:
                zero[:j] += 1
            else:
                zero[j-A[j]:j] += 1
            
    if count == 0:
        break
    else:
        A = zero

L=[str(a) for a 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()))


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)

maxc = 0
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 = []
if maxc == n:
    print(' '.join(map(str, [n] * n)))
    exit()
for i in range(1, n+1):
    res.append(list1.sum(i))
print(' '.join(map(str, res)))

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 p in range(n):
        for q in range(max(p-a[p],0),min(p+a[p]+1,n)):
            b[q] += 1;
    
    yy = 0;
    for v in range(n):
        a[v] = b[v];
        if a[v] == n:
            yy += 1;
    
    if yy == n:
        break;

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

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):
            l = max(0,   j-A[j])
            u = min(N-1, j+A[j])
            for k in range(l, u+1):
                B[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 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):
        start = int(max(0, i - A[i]))
        end = int(min(i + A[i], N - 1))
        B[start:end + 1] += 1
    A = B

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

Submission status: Time Limit Exceeded

Solution code:
def C():
    n,k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    import copy
    pre = copy.copy(a)
    import math
    for _ in range(k):
        tmp = [0]*n
        for i in range(n):
            x_min = 1 if (i+1)-pre[i]-0.5 < 1 else math.ceil((i+1)-pre[i]-0.5)
            x_max = n if (i+1)+pre[i]+0.5 > n else math.floor((i+1)+pre[i]+0.5)
            for j in range(x_min-1,x_max):
                tmp[j] += 1
        pre = copy.copy(tmp)
    print(" ".join(map(str,pre)))
C()

Submission status: Time Limit Exceeded

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

for cnt in range(k):
    if cnt > int(n/2):
        for l in range(n):
            a[l] += k - cnt
    else:
        for i in range(n):
            abl = a[i] * 2 + 1
            for j in range(abl):
                lenge = i - a[i] + j
                if lenge >= 0 and lenge < n:
                    b[lenge] += 1
        a = b
        b = [0] * n

print(*a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

if __name__ == '__main__':
    N, K = map(int, input().strip().split(" "))
    A = np.array(input().strip().split(" ")).astype(int)
    for i in range(K):
        B = np.zeros(N).astype(int)
        for j in range(N):
            for k in range(max(0, j - A[j]), min(j + A[j] + 1, N), 1):
                B[k] += 1
        A = B.copy()
    print(" ".join(A.astype(str)))

Submission status: Time Limit Exceeded

Solution code:
#! -*- coding: utf-8 -*-

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


def in_range(x, n_min, n_max):
    if n_min <= x <= n_max:
        return True
    else:
        return False


lamps = {n+1: [n+1-ac-0.5, n+1+ac+0.5] for n, ac in enumerate(a)}
lamp_counter = {}

for _ in range(k):
    lamp_counter = {nc+1: 0 for nc in range(n)}

    for lamp, r in lamps.items():
        for ncc in range(n):
            if in_range(ncc+1, *r):
                lamp_counter[ncc+1] += 1
    lamps = {n+1: [n+1-ac-0.5, n+1+ac+0.5] for n, ac in enumerate(lamp_counter.values())}

print(*lamp_counter.values())

Submission status: Time Limit Exceeded

Solution code:
import copy

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

new_a = [0 for i in range(n)]
for i in range(k):
    for j in range(n):
        new_a[max(j-a[j], 0)] += 1
        if j+a[j]+1 < n:
            new_a[j+a[j]+1] += -1
    for j in range(n):
        if j > 0:
            new_a[j] += new_a[j-1]
    a = copy.copy(new_a)
    new_a = [0 for i in range(n)]

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