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 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,K = IL()
A = IL()

while True:
  if K == 0:
    break
  SEGLEN = 18
  seg = [0 for i in range(2**(SEGLEN+1))]
  for i in range(N):
    l = max(0,i-A[i])
    r = min(N-1,i+A[i])
    l += 2**SEGLEN
    r += 2**SEGLEN+1
    while l < r:
      if l%2 == 1:
        seg[l] += 1
      if r%2 == 1:
        seg[r-1] += 1
      l = -(-l//2)
      r = r//2
  A = []
  MIN = INF
  for i in range(N):
    i += 2**SEGLEN
    ans = 0
    while i:
      ans += seg[i]
      i //= 2
    A.append(ans)
    MIN = min(MIN,ans)
  K -= 1
  if MIN == N:
    break
  
print(*A)

Submission status: Time Limit Exceeded

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

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

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

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    if K + min(A) >= N:
        print(" ".join(map(str, [N]*N)))
        return

    for i in range(K):
        A_next = [0] * len(A)
        for i, a in enumerate(A):
            A_next[i] += 1
            for d in range(1, a+1):
                idx = i - d
                if idx >= 0 and idx < len(A_next):
                    A_next[idx] += 1

                idx = i + d
                if idx >= 0 and idx < len(A_next):
                    A_next[idx] += 1
        A = copy.deepcopy(A_next)

        if min(A) == N:
            break 

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

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import copy

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

ans = [0] * N
def loop():
    global a
    ruir = [0] * (N + 1)
    ruil = [0] * (N + 1)
    for i in range(N):
        ruir[i] += 1
        tmp = i + a[i]
        if tmp < N:
           ruir[tmp + 1] -= 1
    for i in range(N):
        ruir[i + 1] += ruir[i]

    for i in reversed(range(N)):
        if a[i] - 0.5 > -1:
            ruil[i - 1] += 1
            tmp = i - a[i]
            if tmp > 0:
                ruil[tmp - 1] -= 1
    for i in reversed(range(N)):
        ruil[i - 1] += ruil[i]
    cnt = 0
    for i in range(N):
        add = ruir[i] + ruil[i]
        if add > N:
            add = N
        if add == N:
            cnt +=1
        ans[i] = add
    if cnt == N:
        print(*ans)
        exit()
    a = copy.deepcopy(ans)

for i in range(K):
    loop()
print(*ans)

Submission status: Time Limit Exceeded

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

akarusa = np.array(A)


for k in range(K):
    tmp_akarusa = np.zeros(N, dtype = int)
    for i in range(1,N+1):
        for j in range(1, N+1):
            if abs(j - i) <= akarusa[j-1] + 0.5:
                tmp_akarusa[i-1] = tmp_akarusa[i-1] + 1
    akarusa = tmp_akarusa

a = list(akarusa)
print(*a)

Submission status: Time Limit Exceeded

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

lamp = []
for i in range(len(A)):
    lamp.append(A[i])


def operation(lampList):
    tmpList = [0] * len(lampList)
    allList = [1] * len(lampList)

    for i in range(len(lampList)):
        l = lampList[i] + 1
        if ((l > NK[0] - i) and (l > i)):
            tmpList = np.array(tmpList) + np.array(allList)
        else:
            tmpList[i] += 1
            for j in range(1, l):
                if (i - j >= 0):
                    tmpList[i - j] += 1
                if (i + j < NK[0]):
                    tmpList[i + j] += 1
    return tmpList

for i in range(NK[1]):
    lamp = operation(lamp)

L=[str(a if a < NK[0] else NK[0]) for a in lamp]
L=" ".join(L)
print(L)

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())

if k >= (n//2)+2:
    b = [n] * n
    print(*[b[i] for i in range(n)])
    exit()

for q 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
    
    if b == [n] * n:
        break
    else:
        a = b

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

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 = int(i - a)
            top = int(i + a + 1)
            if bottom < 0:
                bottom = 0
            if top > N:
                top = N
            B[bottom:top] += np.ones(top-bottom)
        A = B[:]

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


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):
  if A==[N]*N:
    break
  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:
N, K = map(int, input().split())
A = list(map(int, input().split()))
NEW_A = [0] * N

for time in range(K):
  if all([max(i, N - i - 1) <= a for i, a in enumerate(A)]):
    for i in range(N):
      A[i] = min(A[i] + K - time, N)
    break
  
  for i in range(N):
    for j in range(-A[i], A[i]+1):
      if i + j in range(N):
        NEW_A[i+j] += 1

  for i in range(N):
    A[i] = NEW_A[i]
    NEW_A[i] = 0

print(*A, sep=' ')

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

def main():
    N,K = inpl()
    Als = inpl()

    up = [0]+ Als
    """for k in range(1,len(up)):
        up[k] += (K-1)"""
    for _ in range(K):
        uup = [0]*(N+1)
        for i,strong in enumerate(up):
            if i != 0:
                a = max(0,i-strong)
                b = min(N+1,i+strong+1)
                uup = [k+1 if a<=j<b else k for j,k in enumerate(uup)]
                """for kk in range(a,b):
                    uup[kk] += 1"""
        up = uup
    res = ' '.join(map(str,up[1:]))
    print(res)

main()

Submission status: Time Limit Exceeded

Solution code:
#from numba import njit
N , K = map(int,input().split())
C = list(map(int,input().split()))
#@njit
def solve(C,N,K):
  A = C
  for j in range(K):
    B = [0]*N
    d = [0]*(N+1)
    for i in range(N):
      l = max([0 , i - A[i]])
      r = min([N-1 , i+A[i]]) + 1
      d[l] += 1
      d[r] -= 1
    B[0]=d[0]
    for i in range(N-1):
      B[i+1] = B[i] + d[i+1]
    A = B
  return(A)
B = solve(C,N,K)
print(' '.join(map(str, B)))

Submission status: Time Limit Exceeded

Solution code:
import threading
N,K= map(int,input().split())
A = list(map(int,input().split()))
T = [0]*N
class loop(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        for j in range(i-A[i],i+A[i]+1):
            if j>=0 and j<=N-1:
                T[j] += 1

thread_list = []
for t in range(K):
    for i in range(N):
        thread = loop()
        thread.start()
        thread_list.append(thread)
    for thread in thread_list:
        thread.join()
    A = T
    T =[0]*N
A=' '.join(map(str,A))
print(A)

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) ]
cnt=0
for i in range(k):
  cnt=0
  b = [ 0 for bi in range(n) ]
  for j in range(n):
    if b[j] == n:
      cnt += 1
      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

  if cnt == n:
    break
  a = b.copy()
    
print(b[0],end="")
for i in b[1:]:
  print(" {}".format(i),end="")
print()

Submission status: Time Limit Exceeded

Solution code:
n, k = (int(v) for v in input().split(" "))
l = [int(v) for v in input().split(" ")]
cnt = len(l)
for _ in range(k): 
    next_l = [0] * cnt
    for i, v in enumerate(l):
        from_idx = max(i - v, 0)
        to_idx = min(i + v, cnt - 1)
        next_l[from_idx:to_idx+1] = [v+1 for v in next_l[from_idx:to_idx+1]]
    l = next_l
print(" ".join([str(i) for i in l]))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N, K = [int(a) for a in input().split()]
    A = [int(a) for a in input().split()]
    # K = 200000
    # T = int(input())
    # A = [int(a) for a in input().split()]
    # T1, T2, T3 = [int(a) for a in input().split()]
    # A = [0] * 100000

    for _ in range(K):
        AA = [1] * len(A)
        for i, ai in enumerate(A):
            for ii in range(ai):
                ii += 1
                if i + ii < len(A):
                    AA[i + ii] += 1
                if i - ii >= 0:
                    AA[i - ii] += 1
        A = AA
    print(' '.join([str(a) for a in A]))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from copy import copy, deepcopy
from collections import Counter
from math import sqrt, floor, factorial
from itertools import permutations, combinations, combinations_with_replacement
from operator import mul
from functools import reduce
import bisect

MOD = 10**9 + 7
INF = float('inf')

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

#A = [0 for i in range(N)]
B = [0 for i in range(N)]

# print(A)
for _ in range(K):
    for i in range(N):
        B[i] = 0
    for i in range(N):
        tmp = A[i]
        B[max(i-tmp, 0)] += 1
        idx = min(i+tmp+1, N)
        if idx != N:
            B[idx] -= 1
    # print(B)
    for i in range(N-1):
        B[i+1] += B[i]
    # print(B)
    for i in range(N):
        A[i] = B[i]
    if sum(A) == N**2:
        break

L = " ".join([str(x) for x in A])
print(L)

Submission status: Time Limit Exceeded

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


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

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

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

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

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

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


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


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

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


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

Submission status: Time Limit Exceeded

Solution code:
# -*- 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):
    for x in range(N):
      if((o-AK[m-1][o]+0.5) < (x+1)) and ((x+1) < (o+AK[m-1][o]+1.5)):
        AK[m][x] = AK[m][x] +1
print(*AK[m])

Submission status: Time Limit Exceeded

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

for i in range(K):
  R = [ {} for j in range(N)]

  for j in range(N):
    s = A[j]
    # j - s ~ j + s
    if min(j+s, N-1) in R[max(0, j-s)]:
      R[max(0, j-s)][min(j+s, N-1)] += 1
    else:
      R[max(0, j-s)][min(j+s, N-1)] = 1
        
  # Make Next List
  #print(R)
  B = [0 for j in range(N)]
  L = [0 for j in range(N)]
  t = 0
  for j in range(N):
    r = R[j]
    for k, v in r.items():
      t += v
      L[k] += v
    B[j] = t
    t -= L[j]
    
  #Merge
  A = [ B[j] for j in range(N)]
  for j in range(N):
    if A[j] < N:
      break
  else:
    break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
d_ls=[int(z) for z in input().split()]

for kk in range(k):
  b=[0]*n
  for i,d in enumerate(d_ls):
    i_front=i+d+0.5
    i_back=i-d-0.5
    for ii,dd in enumerate(d_ls):
      if i_front>=ii>=i_back:
        b[ii]+=1
  for iii,bbb in enumerate(b):
    d_ls[iii]=bbb

bl=[str(a) for a in b]
bl=" ".join(bl)
print(bl)

Submission status: Time Limit Exceeded

Solution code:
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=[0]*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:
import copy
import math
 
n,k=map(int,input().split())
a=list(map(int,input().split()))
 
tokuans=[n for i in range(n)]
flag=0
if k>=math.sqrt(2*n)+1:
    a=tokuans
else:
    for i in range(k):
        tmp=[]
        for i in range(n):
            tmp.append(1)
        for num, i in enumerate(a):
            if tmp==tokuans:
                flag=1
                break
            for j in range(i):
                j+=1
                if  num+j<n:
                    tmp[num+j]+=1
                if 0<=num-j:
                    tmp[num-j]+=1
        a=tmp
        if flag==1:
            break
 
ans=""
for i in a:
    ans+=str(i)+" "
print(ans[0:-1])

Submission status: Time Limit Exceeded

Solution code:
def get_lump(target_list, num):
    result_list = [0] * num
    for target_num in range(len(target_list)):
        min_range = target_num - target_list[target_num] - 0.5
        max_range = target_num + target_list[target_num] + 0.5
        for result_num in range(len(result_list)):
            if min_range < result_num < max_range:
                result_list[result_num] += 1
    return result_list


def main():
    total = list(map(int, input().split()))
    akarusa = list(map(int, input().split()))

    for i in range(total[1]):
        akarusa = get_lump(akarusa, total[0])

    kaitou = ''
    for j in range(len(akarusa)):
        if kaitou == '':
            kaitou = str(akarusa[j])
        else:
            kaitou = kaitou + ' ' + str(akarusa[j])

    print(kaitou)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from numba import njit
N , K = map(int,input().split())
C = list(map(int,input().split()))
@njit
def solve(C,N,K):
  A = C
  for j in range(K):
    B = [0]*N
    d = [0]*(N+1)
    for i in range(N):
      l = max([0 , i - A[i]])
      r = min([N-1 , i+A[i]]) + 1
      d[l] += 1
      d[r] -= 1
    B[0]=d[0]
    for i in range(N-1):
      B[i+1] = B[i] + d[i+1]
    A = B
  return(A)
B = solve(C,N,K)
print(' '.join(map(str, B)))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
import numpy as np
A = list(map(int,input().split()))
A = np.array(A)
if N<K:
    oppai = [N]*N
    print(*oppai)
    exit()




for k in range(K):
    counterlist = np.array([0]*N)
    for i in range(N):
        d = A[i]
        u = max(0,i-d)
        v = min(N-1,i+d)
        counterlist[u:v+1]+=1
    if all(A==counterlist):
        print(*A)
        break
    A = counterlist

    
        

else:
    print(*A)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(k):
        tmp = [0] * n
        count = 0
        for j in range(n):
            for k in range(max(0, j - a[j]), min(n, j + a[j] + 1)):
                tmp[k] += 1
                if tmp[k] == n:
                    count += 1
        a = tmp
        if count == n:
            break
    print(*a)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

Solution code:
def C():
    n,k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    pre = {}
    for i in range(n):
        pre[i+1] = a[i]
    import collections
    for _ in range(k):
        tmp = []
        for i in range(n):
            x_min = 1 if (i+1)-pre[(i+1)] < 1 else (i+1)-pre[(i+1)]
            x_max = n if (i+1)+pre[(i+1)] > n else (i+1)+pre[(i+1)]
            tmp.extend(range(x_min,x_max+1))
        pre = collections.Counter(tmp)
        if min(pre) == n:
            break
    s = ""
    for i in range(1,n+1):
        if s != "":
            s += " "
        if i not in pre:
            s += str(0)
        else:
            s += str(pre[i])
    print(s)
C()

Submission status: Time Limit Exceeded

Solution code:
import copy
#貪欲じゃダメ？→ダメでした(それはそう)
n,k=map(int,input().split())
A=list(map(int,input().split()))
#イメージ的には真ん中へんからマックスになって
#最終的には全部マックスになるイメージ
#そういや全部ゼロなら一生動かないな
#全部マックスでも一生動かないけど
pA=[-1]*n
B=[0]*n
for z in range(k):
  for i in range(n):
    d=A[i]
    pd=pA[i]
    if pd!=-1:
      if d!=pd:
        #違うってことは延びてる
        for j in range(d-pd):
          if i-d+j>=0:
            B[i-d+j]+=1
          if i+d-j<n:
              B[i+d-j]+=1
    else:
      for j in range(2*d+1):
        if i-d+j>=0 and i-d+j<n:
          B[i-d+j]+=1
  pA=copy.deepcopy(A)
  A=copy.deepcopy(B)
print(*A)

Submission status: Time Limit Exceeded

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,K = IL()
A = IL()

while True:
  if K == 0:
    break
  if min(A) == N:
    break
  SEGLEN = 18
  seg = [0 for i in range(2**(SEGLEN+1))]
  for i in range(N):
    l = max(0,i-A[i])
    r = min(N-1,i+A[i])
    l += 2**SEGLEN
    r += 2**SEGLEN+1
    while l < r:
      if l%2 == 1:
        seg[l] += 1
      if r%2 == 1:
        seg[r-1] += 1
      l = -(-l//2)
      r = r//2
  A = []
  for i in range(N):
    i += 2**SEGLEN
    ans = 0
    while i:
      ans += seg[i]
      i //= 2
    A.append(ans)
  K -= 1
  
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import copy
N,K = map(int,input().rstrip().split(" "))
A0 = list(map(int,input().rstrip().split(" ")))
A1 = [0 for i in range(N)]
imos = [0 for i in range(N + 1)]
P = 0
flag = True
counter = 0
while flag:
    for i in range(N+1):
        imos[i] = 0
        if i != N:
            A1[i] = 0
        P = 0
    for i in range(N):
        imos[max(0,i - A0[i])] += 1
        imos[min(N,i + A0[i] + 1)] -= 1
    if imos[0] == N and imos[N] == -1 * N:
        flag = False
    for i in range(N):
        P += imos[i]
        A1[i] = P
    counter += 1
    if counter == K:
        break
    A0 = copy.deepcopy(A1)
print(" ".join(list(map(str,A1))))

Submission status: Time Limit Exceeded

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

def imos(n,a):
  imos_l=[0 for i in range(n)]

  for i in range(n):
    x=i
    x_left=max(x-a[i],0)
    x_right=min(x+a[i],n-1)

    imos_l[x_left]+=1
    if (x_right+1)!=n:
      imos_l[x_right+1]-=1

  b=[0]
  for i in range(1,n+1):
    b.append(imos_l[i-1]+b[i-1])

  return(b[1:])

for i in range(k):
  a=imos(n,a)

  if a.count(n)==n:
    break

print(*a)

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):
        newA = [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 newA == A:
            break
        A = newA
        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:
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]
        if p==N:
            continue
        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))