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 itertools
import numba

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

@numba.jit
def answer(N,K,A):
    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)]
        if len(A) == A.count(len(A)):
            #print("OK")
            break
    return A

A = answer(N,K,A)
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
readline = sys.stdin.buffer.readline
def main():
  n,k=map(int,readline().split())
  a=np.array(list(map(int,readline().split())))
  nums=np.array(range(n))
  leftdis=nums-a-0.5
  rightdis=nums+a+0.5
  for j in range(k):
    for i in range(n):
      a[i]=np.count_nonzero(np.logical_and(leftdis<i,rightdis>i))
    #leftdis[i]=a_i-i-0.5
    #rightdis[i]=a_i+i+0.5
    leftdis=nums-a-0.5
    rightdis=nums+a+0.5
  print(" ".join((str(x) for x in a)))
main()

Submission status: Time Limit Exceeded

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

def light(a_list):
    outcome= [0]*n
    for i in range(n):
        for j in range(max(0,i-a_list[i]),min(n,i+a_list[i]+1)):
            outcome[j] += 1
    return outcome

for _ in range(k):
    if sum(a) >= n*n:
        break
    a = light(a)

[print(aa,end=' ') for aa in a]

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, k = map(int, input().split())
arr = np.array(list(map(int, input().split())))


for _ in range(k):
    tmp = np.zeros(n + 2, np.int32)
    for i in range(n):
        power = arr[i]
        left = max(0, i - power + 1)
        right = min(n + 1, i + power + 2)
        tmp[left] += 1
        tmp[right] -= 1
    arr = np.cumsum(tmp)[1:-1]

print(*arr)

Submission status: Time Limit Exceeded

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

#n,k=5,2
#a=[1,0,0,1,0]

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

for i in range(n):
    dp[0][i]=a[i]
    
for ki in range(1,k+1):
    ims=[0]*(n+1)
#    print("ki:",ki,"dp[ki-1]:",dp[ki-1])
    for ni in range(n):
#        print("1:",ni,ni-dp[ki-1][ni],ni+dp[ki-1][ni]+1)
        if 0>ni-dp[ki-1][ni]:
            ims[0]+=1
        else:
            ims[ni-dp[ki-1][ni]]+=1
        if n<ni+dp[ki-1][ni]+1:
            ims[n]-=1
        else:
            ims[ni+dp[ki-1][ni]+1]-=1
#        print("ni:",ni,"ims:",ims)
#    print(ki,"ims:",ims)
    imsi=0
    for ni in range(n):
        imsi+=ims[ni]
        dp[ki][ni]=imsi
#    print(dp[ki])
           
for i in range(n):
    print(dp[k][i],end=" ")
print()

Submission status: Time Limit Exceeded

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

class segtree:
    x_unit=0 # 要素として入れられる最大値
    def __init__(self,N):
        self.n=(1<<len(bin(N-1)[2:]))
        self.x=[self.x_unit]*(2*self.n)

    def build(self, seq):
        for i,j in enumerate(seq, start=self.n):  # n番目からseqをx配列に移していく
            self.x[i] = j
        for i in range(self.n-1, 0, -1):
            self.x[i] = 0
            # セグ木トーナメント表の左右を比較
            # 例えばn=8の時、seq[4]はx[12]に、seq[5]はx[13]に入っている
            # さらにx[14]とx[15]の間に来るのはx[7]、x[12]とx[13]の間に来るのはx[6]

    def fold(self,l,r): # 区間[l, r)値に+1 
        l+=self.n
        r+=self.n-1
        while l<r:
            if l%2==1: # lが奇数
                self.x[l]+=1
                l+=1 # 偶数に調節
            if r%2==0: # rが偶数
                self.x[r]+=1
                r-=1 # 開区間なので1個前は奇数番目の要素
            l //= 2
            r //= 2
        if l==r:
            self.x[l]+=1
        #print(self.x)
    def get(self,i): # seq[i]に対する値を取得 
        i+=self.n
        ret=self.x[i]
        while i>1:
            i //= 2
            ret+=self.x[i]
        return ret

for z in range(k):
    seq=[0]*n
    q=[(max(0, i-a[i]), min(n,i+a[i]+1)) for i in range(n)]
    seg=segtree(n)
    seg.build(seq)
    for i in range(n):
        l,r=q[i]
        seg.fold(l,r)
    ans=[]
    for i in range(n):
        ans.append(seg.get(i))
        
    a=ans+[]
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]

    flag = False
    for i in range(1,k+1):
        pos = [0]*n
        neg = [0]*n

        for j in range(n):
            pwr = dp[i-1][j]
            pos[max(0,j-pwr)]+=1
            neg[min(n-1,j+pwr)]+=1

        ac_pos = 0
        ac_neg = 0
        for j in range(n):
            ac_pos += pos[j]
            ac_neg += neg[j]
            pos[j] = ac_pos
            neg[j] = ac_neg

        if pos[0]==n and neg[n-1]==n:
            flag = True
            break

        dp[i][0] = pos[0]
        for j in range(1,n):
            dp[i][j] = pos[j] - neg[j-1]
    
    if flag:
        for j in range(n-1):
            print(n, end=" ")  
        print(n)

    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:
import numpy as np
N, K = map(int,input().split())
A = np.array(list(map(int, input().split())))

l_n=list(range(N))
l_k=list(range(K))

for _ in l_k:
    result = np.array([0]*N)
    
    for i in l_n:
        _idx_st = i - A[i]
        idx_st = 0 if _idx_st < 0 else _idx_st
        _idx_end = i + A[i]
        idx_end = N if _idx_end >= N else _idx_end + 1

        result[idx_st:idx_end]+=1
    A=result
print(*result)

Submission status: Time Limit Exceeded

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

A = A + [0]
for k in range(K):
    t = [0]*(N+1)
    for i in range(N):
        l = max(i-A[i], 0)
        r = min(i+A[i], N-1)
        t[l] += 1
        t[r+1] -= 1

    S = [0]*N
    S[0] = t[0]
    for i in range(1, N):
        S[i] = S[i-1] + t[i]

    A = S.copy()

print(*S)

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:
    b_list += np.array([0]*max(0,i-ai) + [1]*(n-max(0,i-ai)-max(0,n-(i+1+ai))) + [0]*max(0,n-(i+1+ai)))
    i += 1
  a_list = b_list

print(*a_list)

Submission status: Time Limit Exceeded

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

while  k <K:
	for i in range(N):
		for h in range(-A[i],A[i]+1):
			if i+h>=0 and i+h<=N-1:
				L[i+h]+=1
	A=L
	L=[0]*N
	k+=1
	if all(A[i]==N for i in range(N)):
		break

Astr=[str(a) for a in A]
print(" ".join(Astr))

Submission status: Time Limit Exceeded

Solution code:
n,k,*a=map(int,open(0).read().split())
r=range(n)
while k:
 k-=1;b=[0]*n*3
 for i in r:t=a[i];b[max(0,i-t)]+=1;b[i-~t]-=1
 for i in r:b[i+1]+=b[i]
 if min(a:=b[:n])==n:break
print(*a)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
N,K=map(int,input().split())
a=[0]*N
a=list(map(int,input().split()))
A=np.array(a)
b=np.zeros(N)
for i in range(K):
    b=np.zeros(N)
    for j in range(N):

        minmin=max(0,math.ceil(j-A[j]-0.5))

        maxmax=min(N,math.floor(j+A[j]+0.5)+1)

        if(minmin==maxmax):
            maxmax=maxmax+1
            if(N<=maxmax):
                minmin=N-1
                maxmax=N

        for k in range(minmin,maxmax):
            b[k]=b[k]+1

    A=b
A=A.astype(np.int)
da=list(A)
L=[str(a) for a in da]

da=" ".join(L)
print(da)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, input().split())
# 文字列の入力
#s = input()
#開業されたN個要素を受け付ける
input_list = list(map(int, input().split()))

for i in range(K):
    if input_list == [N for i in range(N)]:
        break
    tmp_list = []
    for j in range(N):
        tmp = 0
        for l in range(N):
            if abs(j-l) <= input_list[l]:
                tmp = tmp+1
        tmp_list.append(tmp)

    input_list = tmp_list

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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 = np.zeros(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] += np.ones(top-bottom)
        A = list(map(int, B))

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

    A_ = list(A)
    for k in range(K):
        B = [0]*(N)
        for i in range(N):
            a = A_[i]
            l = max(0, i-a)
            r = min(N-1, i+a)
            for j in range(l, r+1):
                B[j] += 1
        A_ = list(B)
    print(*A_)
main()

Submission status: Time Limit Exceeded

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

for i in range(k):
  b = [ 0 for bi in range(n) ]
  for j in range(n):
    if b[j] == n:
      continue
    b[j] += 1
    for bb in range(a[j]):
      if  j + bb + 1 < n :
        b[j + bb + 1] += 1
      if  j - bb - 1 >= 0 :
        b[j - bb - 1] += 1

  allflg = True
  for ii in range(len(b)):
    a[ii] = b[ii]
    if b[ii] != n:
      allflg = False
  if allflg == True:
    break
    
print(b[0],end="")
for i in b[1:]:
  print(" {}".format(i),end="")
print()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import njit

N, K = list(map(int, input().strip().split()))
A = np.array(input().strip().split(), dtype=int)
@njit
def calc(A, step):
    b = np.array([0]*N)
    for i in range(N):
        left = int(max(0, i-A[i]))
        right = int(min(N-1, i+A[i]))
        b[left:right+1] +=1
 
    A = b.copy()
    if step < K:
        step += 1
        return calc(A, step)
    else:
        return A
ans = calc(A, 1)
ans = [str(x) for x in ans]
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
n, k =map(int, input().split())
light = list(map(int, input().split()))
             
def sousa(list):
  if sum(list) == n*n:
    return list
    exit()
  new_list = [0]*len(list)
  for i,a in enumerate(list):
#    print('i:{},a:{}'.format(i, a))
    for j in range(i-a, i+a+1):
#      print('j:{}'.format(j))
      if j >= 0 and j <= len(list)-1:
        new_list[j] += 1
  return new_list

for _ in range(k):
  light = sousa(light)
  
ans = ' '.join([str(a) for a in light])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy as cp
n,k = map(int,input().split())
lamps = list(map(int,input().split()))
for j in range(k):
    lamp_io = [0]*n
    for i in range(len(lamps)):
        if(i == 0):
            for k in range(1,lamps[i]+1):
                if(i+k <= n-1):
                    lamp_io[k] += 1
                else:
                    break
            lamp_io[i] += 1
        elif(i == n-1):
            for k in range(1,lamps[i]+1):
                if(i-k >= 0):
                    lamp_io[i-k] += 1
                else:
                    break
            lamp_io[i] += 1
        else:
            for k in range(1,lamps[i]+1):
                a = 0
                b = 0
                if(i+k <= n-1):
                    lamp_io[i+k] += 1
                else:
                    a = 1
                if(i-k >= 0):
                    lamp_io[i-k] += 1
                else:
                    b = 1
                if(a == 1 and b == 1):
                    break
            lamp_io[i] += 1
        # print(lamp_io)    
    lamps = cp.copy(lamp_io)
ans = ""
for i in range(len(lamp_io)):
    ans += str(lamp_io[i]) +" "
print(ans.rstrip())

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [1 for _ in range(n)]
pre_a = [0 for _ in range(n)]

for i in range(k):
  for j in range(n):
    for r in range(min(j+pre_a[j]+1, n), min(j+a[j]+1,n)):
      b[r] += 1
    for r in range(max(0,j-a[j]), max(0,j-pre_a[j])): 
      b[r] += 1
      
  pre_a = a[:]
  a = b[:]
  
  if(min(a) == n):
    break
  
ans = ""
for i in range(n):
  ans += str(a[i]) + " "
print(ans[:-1])

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A2 = [0]*N
for i in range(K):
    for j in range(N):
        g = math.ceil(j+1-A[j]-0.5)
        if g<1:
            g=1
        h = math.floor(j+1+A[j]+0.5)
        if h>N:
            h=N
        for x in range(g,h+1):
            A2[x-1]+=1
    A=A2[:]
    A2 = [0]*N

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):
  lamp = [0]*N
  for j in range(N):
    lamp[max(0,j-A[j]):min(N,1+j+A[j])] = map(lambda x:x+1,lamp[max(0,j-A[j]):min(N,1+j+A[j])])
  A=lamp[:]
print(" ".join(list(map(str,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
        for i, d in enumerate(dists):
            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(dists) == number:
            # すべての光が両端まで届く，変化しなくなる。
            print('Over', xx)
            break

    print(*dists)


if __name__ == '__main__':
    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):
    cnt=[0]*N
    if min(A)>N:
        A=[N]*N
        print(" ".join(str(x) for x in A))
        exit()
    for j in range(N):
        p=A[j]
        for k in range(max(0,j-p),min(j+p+1,N)):
                cnt[k]+=1
    A=cnt

print(" ".join(str(x) for x in A))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import copy
import math
def main():
    N, K = map(int, input().split())
    a = [float(i) for i in input().split()]
    A = [0] * (N + 1)
    if K >= N:
        for i in range(1, N+1):
            if i > 1:
                print(' ', end='')
            print(N, end='')
        print()
        sys.exit()
    for i in range(1, N+1):
        A[i] = a[i - 1]
    for _ in range(K):
        count = [0] * (N + 1)
        for i in range(1, N+1):
            if A[i] >= N:
                left_d = 1
                right_d = N
            else:
                left_d = math.ceil(i - A[i] - 0.5)
                right_d =  math.floor(i + A[i] + 0.5)
                if left_d < 1:
                    left_d = 1
                if right_d > N:
                    right_d = N
            for j in range(left_d, right_d+1):
                count[j] += 1
        A = copy.copy(count)
        flag = True
        for i in range(1, N+1):
            if A[i] != N:
                flag = False
                break
        if flag:
            break
    for i in range(1, N+1):
        if i > 1:
            print(' ', end='')
        print(A[i], end='')
    print()


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

B=[0 for _ in range(n)]

for K in range(k):
    for i in range(n):
        num=A[i]
        for j in range(max(0,i-num),min(n,i+num+1)):
            B[j] +=1
    A=B
    B=[0 for _ in range(n)]
print(*A)

Submission status: Time Limit Exceeded

Solution code:
N_K = input().split()
N = int(N_K[0])
K = int(N_K[1])
A = input().split()
A = [int(i) for i in A]

for k in range(K):
    P = [0]*N
    for a in range(N):
        x = int(a+1-A[a]-0.5)
        y = int(a+1+A[a]+0.5)
        if x < 0:
            x = 0
        elif y > N:
            y = N
        P[x:y] = [j+1 for j in P[x:y]]
    if A == P:
        break
    A = P
print(' '.join(map(str,P)))

Submission status: Time Limit Exceeded

Solution code:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def f(N, K, A):
    p = 0
    for i in range(K):
        C = np.zeros(N, dtype=np.int64)
        for j, a in enumerate(A):
            C[max(0, j - a):min(j + a + 1, N)] += 1
        A = C

        if len(set(A)) == 1:
            p += 1
            if p == 2:
                break
    return A


def solver():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    A = f(N, K, A)
    print(*A)


solver()

Submission status: Time Limit Exceeded

Solution code:
from numpy import zeros

N,K=(int(x) for x in input().split())
#print(N)
#print(K)

A=input().split()
#print(type(A))
for count in range(K):
  Anew=zeros(N)
  for i in range(N):
    for k in range(N):
      if abs(i-k)<=int(A[k]):
        Anew[i]+=1
 #       print(i,k,Anew[i])

  if count==K-1:
    for i in Anew:
      print(int(i),end=" ")
  A=Anew

Submission status: Time Limit Exceeded

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for _ in range(K):
    tmp = [0]*N
    for i in range(N):
        left = max(0, i-A[i])
        right = min(N-1, i+A[i])
        for j in range(left, right+1):
            tmp[j] += 1
    A = tmp[:]
    if all([N == x for x in A]):
        break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))  # 整数のリスト

    next_A = [0 for _ in range(N)]

    for _ in range(K):
        cnt = 0
        if sum(A) == N**2:
            # print("break")
            break
        for i in range(N):
            if A[i] >= N:
                cnt += 1
                # print("continue")
                continue
            for j in range(i-A[i], i+A[i]+1):
                if j >= 0 and j < N:
                    next_A[j] += 1
        next_A = list(map(lambda x: x + cnt, next_A))
        A = next_A
        next_A = [0 for _ in range(N)]

    for i in A:
        print(i, end=" ")

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10 ** 7)

N, K = map(int, input().split())
# A = np.array(list(map(int, (input().split()))))
A = list(map(int, (input().split())))
# nd = np.zeros((N,N), dtype=bool)
# print(*A)
for i in range(min(K,N)):
    cnt = [0]*N
    for j in range(N):
        # nd[j, max(j-A[j],0):min(j+A[j]+1,N)] = True
        for k in range(max(j-A[j],0), min(j+A[j]+1,N)):
            cnt[k] += 1
    # print(nd)
    A = copy.copy(cnt)
    # print(*A)

print(*A)

Submission status: Time Limit Exceeded

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

for k in range(K):
  llist = []
  for i, a in enumerate(A):
    l = list(range(i-a+1, i+a+2))
    llist.extend(l)
  for i, a in enumerate(A):
    A[i] = llist.count(i+1)

print(*A)

Submission status: Time Limit Exceeded

Solution code:
import copy

N, K = [int(x) for x in input().strip().split(" ")]
A = [int(x) for x in input().strip().split(" ")]

for _ in range(K):
    A = [
        len([1 for j in range(N) if A[j] >= abs(i - j)])
        for i in range(N)
    ]
print(" ".join([str(a) for a in A]))

Submission status: Time Limit Exceeded

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

# 0番地は使わない、座標iが1から始まるのでそれにあわせて0番地をゼロで埋めておく
lights_before = list(map(int, input().split(' ')))
lights_before.insert(0, 0)
lights_after = [0] * (N + 1)
#print(N,K)
#print(lights_before)
#print(lights_after)

# K回操作を繰り返す
# 
for i in range(K):
  if(i > 0):
      lights_before = lights_after
      lights_after = [0] * (N + 1)
      #print("lights_beforeは", lights_before)
      #print("lights_afterは", lights_after)
  for x in range(1, N + 1):
    # x - lights_before[x] 〜 x + lights_before[x]までカウントアップしておく
    # それぞれが要素番地をオーバーフローしないようにする
    #print("座標は{0}, 光の強さは{1}".format(x, lights_before[x] ))
    start = 0
    end = 0
    if (x - lights_before[x] < 1):
      start = 1
    else:
      start = x - lights_before[x]
    
    if (x + lights_before[x] > N):
      end = N
    else:
      end = x + lights_before[x]
      
    #print("startは{0}, endは{1}".format(start, end))
    
    for z in range(start, end + 1):
      lights_after[z] += 1
    
    #print("{0}番地処理後".format(x))
    #print(lights_after)
    
# 0番地を除去してstringで列挙
lights_after.pop(0)
print(' '.join(map(str,lights_after)))

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
a = na()

def calc_lux(a):
    res = [0 for _ in range(len(a))]
    cnt = 0
    for i in range(len(a)):
        light = a[i]
        if light==len(a):
            cnt += 1
            continue
        for j in range(max(0, i-light), min(n-1, i+light)+1, 1):
            res[j] += 1
    for i in range(len(res)):
        res[i] += cnt
    return res

for _ in range(k):
    # calc lux from a
    lux = calc_lux(a)

    if a==lux:
        a = lux
        break

    # overwrite a
    a = lux
    # print(lux)

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()))
event = []
data = [0 for _ in range(n+1)]
for i in range(k):
    data = [0 for _ in range(n + 1)]
    for i in range(n):
        data[max(0,i-a[i])] += 1
        data[min(n,i+a[i]+1)] -= 1

    for i in range(n):
        data[i+1] += data[i]

    a = data
print(*a[:n])

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for k in range(K):
  B = [0] * N
  for i in range(N):
    s = i - A[i]
    if s < 0:
      s = 0
    l = i + A[i] + 1
    if l >= N:
      l = N
    for j in range(s, l):
      B[j] += 1
  A = B
    
for b in B:
  print(b, end=" ")

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
p=[n]*n
if k>=n:
  print(*p)
  exit()
b=[0]*n
for l in range(k):
  b=[0]*n
  count=0
  for i in range(n):
    c=a[i]
    b[i]+=1
    if c>0:
      for j in range(c):
        if (i-c+j)<0 and (i+c-j)>=n:
          continue
        elif (i-c+j)<0:
          b[i+c-j]+=1
        elif (i+c-j)>=n:
          b[i-c+j]+=1
        else:
          b[i-c+j]+=1
          b[i+c-j]+=1
  a=b
  if len(set(a))==1 and a[0]==n:
    print(*p)
    exit()
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()))
    A_temp=[0]*N
    for k in range(K):
        for i,data in enumerate(A):
            for j in range(max(0,i-data),min(N,i+data+1)):
                A_temp[j]+=1
        A=A_temp
        A_temp=[0]*N
    print(*A)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n,k,*a,=map(int,open(0).read().split())
def f(li):
	b=[0]*(n+1)
	for i,x in enumerate(li):
		b[max(0,i-x)]+=1
		b[min(i+x+1,n)]-=1
	for i in range(n):
		b[i+1]+=b[i]
	return b[:-1]
for _ in range(k):
	a=f(a)
	if a==[n]*n:
		print(*a)
		exit()
print(*a)

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)]
if (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:
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)]

if K >= N:
    L=[str(length) for a in range(N)]
    L=" ".join(L)
    print(L)
    exit()
else:
    for i in range(K):
        count = 0
        zero = np.array([0]*N)
        for j in range(N):
            if A[j] == length:
                zero += 1
            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:
def incr(n):
  return n+1

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

for i in range(K):
  B = [0]*len(A)
  for j in range(len(A)):
    llim = max([0, j-A[j]])
    ulim = min([len(A), j+A[j]+1])
    B[llim:ulim] = list(map(incr, B[llim:ulim]))
  A=B

print(*A)

Submission status: Time Limit Exceeded

Solution code:
def adjust_light(arr):
    values = []
    counter = [0] * len(arr)
    
    for idx in range(0, len(arr)):
        min = idx - arr[idx]
        if min < 0:
            min = 0
        max = idx + arr[idx]
        if max >= len(arr):
            max = len(arr)-1
        values.extend(range(min, max+1))
    for val in values:
        counter[val] = counter[val] + 1
    return counter

n, k = list(map(int, input().split(' ')))
arr = list(map(int, input().split(' ')))
for idx in range(0, k):
    arr = adjust_light(arr)
print(*arr)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.insert(0,0)
X = {i:0 for i in range(-2*N,4*N+2)}
k = 0
while k<K:
    for i in range(1,N+1):
        d = A[i]
        X[2*i-2*d-1] += 1
        X[2*i+2*d+1] -= 1
    for i in range(-2*N+1,4*N+2):
        X[i] += X[i-1]
    for i in range(1,N+1):
        A[i] = X[2*i]
    X = {i:0 for i in range(-2*N,4*N+2)}
    cnt = 0
    for i in range(1,N+1):
        cnt += A[i]
    if cnt==N*N:
        break
    k += 1
print(*A[1:])

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(v) for v in input().strip().split(" ")]
A = [int(v) for v in input().strip().split(" ")]

for i in range(K):
    new_A = [0] * N
    for x in range(N):
        for k in range(max(x - A[x], 0), min(x + A[x] + 1, N)):
            new_A[k] += 1
    A = new_A

print(A[0], end="")
for i in range(1, N):
    print(" %s" % A[i], end="")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
A = input().split()
AK = [[0 for j in range(N)] for i in range(K+1)]
for l in range(N):
  AK[0][l] = int(AK[0][l]) + int(A[l])

for m in range(1,K+1,1):
  for o in range(N):
    d = AK[m-1][o]
    if d != N+1:
      for x in range(N):
        if((o+1-d-0.5) < (x+1)) and ((x+1) < (o+1+d+0.5)):
          AK[m][x] = AK[m][x] +1
print(*AK[m])

Submission status: Time Limit Exceeded

Solution code:
N,K = [int(v) for v in input().split()]
A = [int(v) for v in input().split()]

N_count = A.count(N)
N_flag = [False for _ in range(N)]

for _ in range(K):
    next_A = [0 for _ in range(N+1)]
    for x,a in enumerate(A):
        if a == 0:
            next_A[x] += 1
            next_A[x+1] -= 1
        else:
            next_A[max(x-a,0)] += 1
            next_A[min(x+a+1,N)] -= 1

    for i in range(N):
        next_A[i+1] += next_A[i]

    A = next_A[:N]
    for x,a in enumerate(A):
        if a == N and not N_flag[x]:
            N_flag[x] = True
            N_count += 1
    if N_count == N:
        break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
A = LI()

"""
明るさが一定値を超えると計算しなくて良い
一定？d > math.floort(N/2)
"""

lamps = [[0] * N] * (K + 1)
lamps[0] = A

lamps = np.array(lamps)

if K > 40:
    b = [str(N)] * N
    print(" ".join(b))
    sys.exit()

for i in range(K):
    if lamps[i][-1] == N:
        if np.all(lamps[i] == np.ones(N) * N):
            ans = [str(N)] * N
            print(" ".join(ans))
            sys.exit()
    for j in range(N):
        tmp = lamps[i][j]
        if tmp == 0:
            lamps[i+1][j] += 1
        else:
            lamps[i + 1][max(0, j - tmp):min(N + 1, j + tmp) + 1] += 1

ans = lamps[-1].tolist()
ans = map(str, ans)
print(" ".join(ans))

Submission status: Time Limit Exceeded

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

for _ in range(K):
  A = [sum([A[nx] >= abs(nx- n) for nx in range(N)]) for n in range(N)]
print(" ".join(map(str,list(map(int,A)))))