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: Runtime Error

Solution code:
import numpy as np

# Get input
N, K = [int(v) for v in input().split(" ")]
A_arr = np.array([int(v) for v in input().split(" ")])
step = np.arange(len(A_arr))

# Trivial solution
if K > N//2+1:
  print(" ".join([str(N)]*N))
  exit()

def get_Intensity(A_arr):
  inten = np.zeros(len(A_arr))
  for i in range(len(A_arr)):
    isLuminated = np.abs(step - i) < A_arr
    inten[i] = np.sum(isLuminated)
  return inten
def loop(N, K, A_arr):
  Intensity = A_arr
  for i in range(K):
    Intensity = get_Intensity(Intensity+1)
    # Termination of calculation (stable solution)
    if np.all(Intensity == N):
      break
  return
#print(" ".join([str(v) for v in Intensity.astype(int)]))
print(' '.join(map(str, A)))

Submission status: Runtime Error

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

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

Defl = np.zeros((n, 3*n+2), dtype = int)


def nextLights(A, Defl):
    Lights =Defl.copy()
    i = 1
    for a in A:
        line = np.ones(a*2+1, dtype = int)
        Lights[i-1][n+i-a:n+i+a+1] += line
        i+=1
    Lights = Lights[:, n+1:2*n+1]
    Next_A = np.sum(Lights, axis=0)
    return Next_A

if k >= 50:
    print((str(n)+" ")*n)
else:
    for i in range(k):
        A = nextLights(A, Defl)
    print(" ".join(str(a) for a in A))

Submission status: Runtime Error

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

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

Defl = np.zeros((n, 3*n+2), dtype = int)


def nextLights(A, Defl):
    Lights =Defl
    i = 1
    for a in A:
        line = np.ones(a*2+1, dtype = int)
        Lights[i-1][n+i-a:n+i+a+1] += line
        i+=1
    Lights = Lights[:, n+1:2*n+1]
    Next_A = np.sum(Lights, axis=0)
    return Next_A

if k >= 50:
    print((str(n)+" ")*n)
else:
    for i in range(k):
        Next_A = nextLights(A, Defl)
        A = Next_A
    print(" ".join(str(a) for a in A))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,k = map(int, input().split())
a1 = list(map(int, input().split()))
a = np.asarray(a1, dtype=int)
if k<int(math.exp(int(n))):
    for i in range(k):
        b = np.zeros(n, dtype=int)
        for j in range(n):
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            b[mi:ma+1]+=1
        a = b
    print(*a)
else:
    ans = np.asarray(n, dtype=int)
    print(*ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math


N, K = list(map(int, input().split()))
lamps = np.array(list(map(int, input().split())), dtype=np.int64)
init = lamps
for i in range(K):
    act = np.zeros((N, N))
    for i in range(N):
        # if init[i] == 0:
        #     continue
        # d = math.floor(init[i] + 0.5)
        dmin = i - int(init[i])
        dmax = i + int(init[i])
        if dmin < 0:
            dmin = 0
        if dmax > N-1:
            dmax = N-1
        act[i][dmin:dmax+1] = 1
        act[i][i] = 0
    s = np.sum(act, axis=0)
    init = s + np.ones(N, dtype=np.int64)
result = init.astype("int64")
ans = list(map(str,result.tolist()))
print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,K = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    print(1)
else:
    else:
        old = A
        for _ in range(K):
            li = [0]*N
            for i in range(N):
                MIN = max(0,i-old[i])
                MAX = min(N-1,i+old[i])
                li[MIN] += 1
                if MAX != N-1:
                    li[MAX+1] -= 1
            old = accumulate(li)
            old = list(old)
            if min(old) == N:
                break
        print(*old)

Submission status: Runtime Error

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

for i in range(K):
    B = [0] * N
    for j in range(N):
        l = max(0,j-A[j])
        r = j+A[j]+1
        B[l] += 1
        if r < N:
            B[r] -= 1
    for j in range(1, N):
        B[j] += B[j-1]

    A = B

    if sum(A) == N**2:
        print(break)

print(*A)

Submission status: Runtime Error

Solution code:
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[0]*5
while k!=0:
    for i in range(n):
        for j in range(i-a[i],i+a[i]+1,1):
            if 0<=j and j<n:
                b[j]+=1
    a=b
    b=[0]*5
    k-=1
print(' '.join(map(str, a)))

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <stdlib.h>

int* light_change(int* A,int N,int K){
    int* B=(int*)malloc(sizeof(int));
    
    int i,j,k;
    for(k=0;k<K;k++){
        for(i=0;i<N;i++){
            B[i]=0;
        }
       for(i=0;i<N;i++){
           for(j=(i-A[i]>=0? i-A[i]:0); j<(i+A[i]+1<=N ? i+A[i]+1: N); j++){
            B[j]++;
        }
    }
    for(i=0;i<N;i++){
        A[i]=B[i];
    }
    }
    free(B);
    return A;
}


int main(void){
    // Your code here!
    int N,K;
    scanf("%d %d",&N,&K);

    int* A=(int*)malloc(sizeof(int)*N);
    
    int i=0;
    for(i=0; i<N;i++){
        scanf("%d",&(A[i]));
    }
    light_change(A,N,K);
    
    
    for(i=0;i<N;i++){
        printf("%d ",A[i]);
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np                       
                                         
N,K,*A = map(int, open(0).read().split())
A = np.array(A)                          
                                         
for _ in range(K):                       
    X = np.ones(N, int)                  
    for i, d in enumerate(A):            
        X[max(0, i-d):max(0, i)] += 1    
        X[i+1:i+d+1] += 1                
    if np.array_equal(X, A):             
        break                            
    A = X                                
                                         
print(" ".join(map(str, A)))

Submission status: Runtime Error

Solution code:
import math
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[0]*5
while k!=0:
    for i in range(n):
        for j in range(i-a[i],i+a[i]+1,1):
            if 0<=j and j<n:
                b[j]+=1
    a=b
    b=[0]*5
    k-=1
print(' '.join(map(str, a)))

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <stdlib.h>

int* light_change(int* A,int N,int K){
    int* B=(int*)malloc(sizeof(int));
    
    int i,j,k;
    for(k=0;k<K;k++){
        for(i=0;i<N;i++){
            B[i]=0;
        }
       for(i=0;i<N;i++){
           for(j=(i-A[i]>=0? i-A[i]:0); j<(i+A[i]+1<=N ? i+A[i]+1: N); j++){
            B[j]++;
        }
    }
    for(i=0;i<N;i++){
        A[i]=B[i];
    }
    }
    free(B);
    return A;
}


int main(void){
    // Your code here!
    int N,K;
    scanf("%d %d",&N,&K);
    printf("%d %d\n",N,K);
    int* A=(int*)malloc(sizeof(int)*N);
    
    int i=0;
    for(i=0; i<N;i++){
        scanf("%d",&(A[i]));
    }
    light_change(A,N,K);
    
    
    for(i=0;i<N;i++){
        printf("%d ",A[i]);
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
import math
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[0]*5
while k!=0:
    for i in range(n):
        for j in range(i-a[i],i+a[i]+1,1):
            if 0<=j and j<n:
                b[j]+=1
    a=b
    b=[0]*5
    k-=1
2
print(' '.join(map(str, a)))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from itertools import accumulate

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

light_intensity = A

for k in range(K):
    new_light_intensity = [0 for i in range(N)]
    # 累積和で求める
    for i in range(N):
        left = max(0, i-light_intensity[i])
        right = min(i+light_intensity[i], N)
        new_light_intensity[left] += 1
        if right+1 < N:
            new_light_intensity[right+1] -= 1
    
    light_intensity = list(itertools.accumulate(new_light_intensity))
    
    if k > 41:
        print(" ".join(map(str, light_intensity)))
        exit(0)

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = np.asarray(a, dtype=int)
if k<int(math.exp(int(n))):
    for i in range(k):
        b = np.zeros(n, dtype=int)
        for j in range(n):
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            b[mi:ma+1]+=1
        a = b.copy()
else:
    a = np.asarray(n, dtype=int)
print(*a)

Submission status: Runtime Error

Solution code:
import numpy as np
import math


N, K = list(map(int, input().split()))
lamps = np.array(list(map(int, input().split())), dtype=np.int64)
init = lamps
for i in range(K):
    act = np.zeros((N, N))
    for i in range(N):
        if init[i] == 0:
            continue
        # d = math.floor(init[i] + 0.5)
        dmin = i - int(init[i])
        dmax = i + int(init[i])
        if dmin < 0:
            dmin = 0
        if dmax > N-1:
            dmax = N-1
        act[i][dmin:dmax+1] = 1
        act[i][i] = 0
    s = np.sum(act, axis=0)
    init = s + np.ones(N, dtype=np.int64)
result = init.astype("int64")
ans = list(map(str,result.tolist()))
print(" ".join(ans))

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <stdlib.h>
 
int* light_change(int* A,int N,int K){
    int* B=(int*)malloc(sizeof(int));
    
    int i,j,k;
    for(k=0;k<K;k++){
        for(i=0;i<N;i++){
            B[i]=0;
        }
       for(i=0;i<N;i++){
           for(j=(i-A[i]>=0? i-A[i]:0); j<(i+A[i]+1<=N ? i+A[i]+1: N); j++){
            B[j]++;
        }
    }
    for(i=0;i<N;i++){
        A[i]=B[i];
    }
    }
    free(B);
    return A;
}
 
 
int main(void){
    // Your code here!
    //int N,K;
    //scanf("%d %d",&N,&K);
    //printf("%d %d",N,K);
    int N=5;
    int K=2;
    int A[]={1,0,0,1,0};
    light_change(A,N,K);
    
    int i=0;
    for(i=0;i<N;i++){
        printf("%d ",A[i]);
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np


def read_input(trans=int):
    return list(map(trans, input().split()))


N, K = read_input()
A = read_input()
K = min(K, 41)

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

        B[start] += 1
        if end+1 < N:
            B[end+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = B.copy()


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

Submission status: Runtime Error

Solution code:
import numpy as np
#import math
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = np.asarray(a, dtype=int)
if k<n:#int(math.exp(int(n))):
    for i in range(k):
        b = np.zeros(n, dtype=int)
        for j in range(n):
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            b[mi:ma+1]+=1
        a = b
else:
    a = np.asarray(n, dtype=int)
print(*a)

Submission status: Runtime Error

Solution code:
import numpy as np

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

for _ in range(K):
    _A = np.array([0]*N)
    
    for i, a in enumerate(A):
        idx_st = max(0, i - a)
        idx_end = max(N - 1, i + a)

        _A[idx_st:idx_end]+=1

    if np.all(result == N):
        break   
    
print(*result)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = np.asarray(a, dtype=int)
if k<n:#int(math.exp(int(n))):
    for i in range(k):
        b = np.zeros(n, dtype=int)
        for j in range(n):
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            b[mi:ma+1]+=1
        a = b
else:
    a = np.asarray(n, dtype=int)
print(*a)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = np.asarray(a, dtype=int)
if k<int(math.exp(int(n))):
    for i in range(k):
        b = np.zeros(n, dtype=int)
        for j in range(n):
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            b[mi:ma+1]+=1
        a = b
else:
    a = np.asarray(n, dtype=int)
print(*a)

Submission status: Runtime Error

Solution code:
import math
def plus(x):
    return x+1

n,k=map(int,input().split())
A=list(map(int,input().split()))
for j in range(math.log2(n)):
    B=[0]*n
    for i in range(n):
        B=B[0:max(0,i-A[i])]+list(map(plus,B[max(0,i-A[i]):min(n,i+A[i]+1)]))+B[min(n,i+A[i]+1):n]
    A=B.copy()

for i in range(n):
    B[i]=str(B[i])

print(' '.join(B))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
from numba import njit
readline = sys.stdin.readline
@njit('i8,i8,i8[::1]',cache=True)
N,K = map(int,readline().split())
A = np.array(readline().split(), dtype=np.int64)
if N==1:
    print(1)
    exit()
if K >= 41:
    for i in range(N-1):
        print(N,end=" ")
    print(N)
    exit()
for k in range(K):
    nextgen = np.zeros(N,dtype=np.int64)
    for i in range(N):
        end = i+A[i]+1
        if end <=N-1:
            nextgen[end] += -1
        nextgen[max(0,i-A[i])] += 1
    dp = 0
    for i in range(N):
        dp += nextgen[i]
        A[i] = dp
print(*A)

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import jit
n, k = map(int, input().split())
a = list(map(int, input().split()))
bb = np.array(a, dtype=np.int64)
# print(bb)
check = np.full(n, n, dtype=np.int64)


@jit
for i in range(k):
    #d = [0] * n
    d = np.zeros(n, dtype=np.int64)
    #temp = bb
    for j in range(1, n + 1):
        pp = bb[j - 1]

        if (pp == 0):
            d[int(j - 1)] += 1
            # print(d)
            continue
        if (pp == n):
            d += 1
            '''
            if (k - i > (n//2)):
                ans = [str(i) for i in check]
                # print(ans)
                print(' '.join(ans))
                exit()
            # print(d)
            '''
            continue

        left = j - bb[j - 1] - 1
        # print(left)
        if (left < 0):
            left = 0
        right = j + bb[j - 1]
        #print('R: ',right)
        if (right > n - 1):
            right = n
        #print('L&R: ', left, right)

        d[int(left): int(right)] += 1
        #print(j, d)

    bb = d

    if (all(bb == check)):
        break


ans = [str(i) for i in bb]
# print(ans)
print(' '.join(ans))

#s = ','.join(l)

Submission status: Runtime Error

Solution code:

import numpy as np


def nextL(A, D):
    L = D
    i = 1
    for a in A:
        line = np.ones(a*2+1, dtype =int)
        L[i-1, n+i-a:n+i+a+1] = line
        i+=1
    L = L[:, n+1:2*n+1]
    Na = np.sum(L, axis=0)
    return Na


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

A = [int(a) for a in input().split()]

D = np.zeros((n, 3*n+2), dtype =int)

if k >= 50:
    print((str(n)+" ")*n)
else:
    for i in range(k):
        Na = nextL(A, D)
        A = Na
    Li=[str(int(a)) for a in A]
    Li=" ".join(Li)
    print(Li)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = np.asarray(a, dtype=int)
if k<int(math.exp(int(n))):
    for i in range(k):
        b = np.zeros(n, dtype=int)
        for j in range(n):
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            b[mi:ma+1]+=1
        a = b
        if np.mean(a)==n:
            break
else:
    for i in range(n):
        a[i] = n
print(*a)

Submission status: Runtime Error

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


def nextL(A, D):
    L = D
    i = 1
    for a in A:
        line = np.ones(a*2+1, dtype =int)
        L[i-1, n+i-a:n+i+a+1] = line
        i+=1
    L = L[:, n+1:2*n+1]
    Na = np.sum(L, axis=0)
    return Na


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

A = [int(a) for a in input().split()]

D = np.zeros((n, 3*n+2), dtype =int)

if k >= 50:
    print((str(n)+" ")*n)
else:
    for i in range(k):
        Na = nextL(A, D)
        A = Na
    Li=[str(int(a)) for a in A]
    Li=" ".join(Li)
    print(Li)

Submission status: Runtime Error

Solution code:
import math
n, k = map(int, input().split())
a_in = list(map(int, input().split()))

diff_list = [0 for num in range(n)]
diff_list[0] = a_in[0]
for i in range(1, n):
    diff_list[i] = a_in[i] - a_in[i-1]

itr = k
if k > 10*math.log(n):
    itr = 10*math.log(n)
for i in range(itr):
    new_list = [0 for num in range(n)]
    d_sum = 0
    for j, d in enumerate(diff_list):
        d_sum += d
        if j-d_sum > 0:
            new_list[j-d_sum] += 1
        else:
            new_list[0] += 1
        if d_sum+j+1 < n:
            new_list[j+d_sum+1] -= 1
    # print(new_list)
    diff_list = new_list.copy()

ans = 0
for d in diff_list:
    ans += d
    print(ans, end= ' ')

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = np.asarray(a, dtype=int)
if k<int(math.exp(n)):
    for i in range(k):
        b = np.zeros(n, dtype=int)
        for j in range(n):
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            b[mi:ma+1]+=1
        a = b
        if np.mean(a)==n:
            break
else:
    for i in range(n):
        a[i] = n
print(*a)

Submission status: Runtime Error

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(K):
   B=[0]*N
   for l in range(N):
      if A[l]==0:
         B[l]+=1
      else:
         for i in range(max(l-A[l],0),min(l+A[l]+1,N),1):
            B[i]+=1
   A=B
print(*A)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(K):
   B=[0]*N
   for l in range(N):
      if A[l]==0:
         B[l]+=1
      else:
         for i in range(max(l-A[l],0),min(l+A[l]+1,N),1):
            B[i]+=1
   A=B
print(' '.join(map(str, A)))

Submission status: Runtime Error

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

K = min(K, math.log(2*10**5))
dp = [[0]*N for _ in range(K)]

for i in range(N):
    temp = S[i]
    m = max(0, i-temp)
    dp[0][m] += 1
    if N > i+temp+1:
        dp[0][i+temp+1] -= 1

for i in range(K-1):
    temp = 0
    for j in range(N):
        temp += dp[i][j]
        m = max(0, j-temp)
        dp[i+1][m] += 1
        if N > j+temp+1:
            dp[i+1][j+temp+1] -= 1

ans = [0]*N
ans[0] = dp[K-1][0]

for i in range(1, N):
    ans[i] = ans[i-1] + dp[K-1][i]

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = np.asarray(a, dtype=int)
if k<math.exp(n):
    for i in range(k):
        b = np.zeros(n, dtype=int)
        for j in range(n):
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            b[mi:ma+1]+=1
        a = b
        if np.mean(a)==n:
            break
else:
    for i in range(n):
        a[i] = n
print(*a)

Submission status: Runtime Error

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(K):
   B=[0]*N
   print(B)
   for l in range(N):
      if A[l]==0:
         B[l]+=1
      else:
         for i in range(max(l-A[l],0),min(l+A[l]+1,N),1):
            B[i]+=1
      print(B)
   A=B
print(' '.join(map(str, A)))

Submission status: Runtime Error

Solution code:
import copy
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [1] * n
for _ in range(math.log(n)):
    for i in range(n):
        light = 0
        for j in range(n):
            if i < j:
                if (j - a[j] - 0.5) < i:
                    light += 1
            else:
                if (j + a[j] + 0.5) > i:
                    light += 1
        b[i] = light
    a = copy.deepcopy(b)
print(a)

Submission status: Runtime Error

Solution code:
N,K,*A = map(int, open(0).read().split())
n = len(A)

def left(i, d):
    if not (0 <= i < n):
        return 0
    v = A[i] - d + 0.5
    if v <= 0:
        return 0 + left(i - 1, d + 1)
    else:
        return 1 + left(i - 1, d + 1)

def right(i, d):
    if not (0 <= i < n):
        return 0
    v = A[i] - d + 0.5
    if v <= 0:
        return 0 + right(i + 1, d + 1)
    else:
        return 1 + right(i + 1, d + 1)

for _ in range(K):
    X = [0 for _ in range(n)]
    for i in range(n):
        l = left(i-1, 1)
        r = right(i+1, 1)
        v = 1 if i < N else 0
        c = v + l + r
        X[i] = c
    if A == X:
        print(" ".join(map(str, A)))
        exit(0)
    A = X

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

Submission status: Runtime Error

Solution code:
import copy
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [1] * n
for _ in range(math.log(k)):
    for i in range(n):
        light = 0
        for j in range(n):
            if i < j:
                if (j - a[j] - 0.5) < i:
                    light += 1
            else:
                if (j + a[j] + 0.5) > i:
                    light += 1
        b[i] = light
    a = copy.deepcopy(b)
print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

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


def nextL(A, D):
    L = D
    i = 1
    for a in A:
        line = np.ones(a*2+1)
        L[i-1, n+i-a:n+i+a+1] = line
        i+=1
    L = L[:, n+1:2*n+1]
    Na = np.sum(L, axis=0)
    return Na


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

D = np.zeros((n, 3*n+2))

if k >= 50:
    print((str(n)+" ")*n)
else:
    #for i in range(k):
    Na = nextL(A, D)
    A = Na
    Li=[str(int(a)) for a in A]
    Li=" ".join(Li)
    print(Li)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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

for _ in range(min(k,math.log(n, 10))):
    new_a = np.zeros(n)
    for j,l in enumerate(a):
        for i in range(-l,l+1):
            if j+i >= 0 and j+i<n:
                new_a[j+i]+=1
    a = new_a

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
n, k = map(int, input().split())

lights = np.array(list(map(int, input().split())))

for _ in range(k):
  if lights.all == n:
    break
  li = lights
  lights = np.array([0]*n)
  for i,x in enumerate(li):
    lights[max(0,i-x):min(n,i+x+1)] += 1

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

Submission status: Runtime Error

Solution code:
import numpy as np

def new_A(N, A):
    _A = np.array([0]*N)
    
    for i, a in enumerate(A):
        _idx_st = i - a
        idx_st = 0 if _idx_st < 0 else _idx_st
        _idx_end = i + a
        idx_end = N if _idx_end >= N else _idx_end + 1

        _A[idx_st:idx_end]+=1
    return _A


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

for _ in range(K):
    A = new_A(N, A)
    if np.all(A == N):
        break   
    
print(*result)

Submission status: Runtime Error

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

#output
#A[i]の電球は i-A[i] から i+A[i]までを照らす。
import numpy as np  

for _ in range(42):
    dp = np.zeros(N, int)
    for i in range(N):
        p = max(0, i-A[i])
        dp[p] += 1
        if i+A[i]+1 <= N-1:
            dp[i+A[i]+1] -= 1
    A = np.cumsum(dp)

if K > 41:
  print(np.array([N]*N, int)
else:
  print(np.cumsum(dp))

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
def solve():
    for k in range(K):
        imos = [0] * (N+1)
        for i,a in enumerate(A):
            l = max(0, i-a)
            r = min(N, i+1+a)
            imos[l] += 1
            imos[r] -= 1
        imos[0] = min(N, imos[0])
        for i in range(N):
            imos[i+1] = min(N, imos[i] + imos[i+1])
        A = imos[:-1]
        if A[0] == A[-1] == N:
            break
    print(*A)
solve()

Submission status: Runtime Error

Solution code:
import numpy as np

# Get input
N, K = [int(v) for v in input().split(" ")]
A_arr = np.array([int(v) for v in input().split(" ")])
step = np.arange(len(A_arr))

# Trivial solution
if K > N//2+11:
  print(" ".join([str(N)]*N))
  exit()

def get_Intensity(A_arr):
  inten = np.zeros(shape=N + 1, dtype=np.int64)
  for i in range(len(A_arr)):
    isLuminated = np.abs(step - i) < A_arr
    inten[i] = np.sum(isLuminated)
  return inten

Intensity = A_arr
for i in range(K):
  Intensity = get_Intensity(Intensity+1)
  # Termination of calculation (stable solution)
  if np.sum(Intensity) == N**2:
    break
#print(" ".join([str(v) for v in Intensity.astype(int)]))
print(' '.join(map(str, A)))

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
for k in range(K):
    imos = [0] * (N+1)
    for i,a in enumerate(A):
        l = max(0, i-a)
        r = min(N, i+1+a)
        imos[l] += 1
        imos[r] -= 1
    imos[0] = min(N, imos[0])
    for i in range(N):
        imos[i+1] = min(N, imos[i] + imos[i+1])
    A = imos[:-1]
    if A[0] == A[-1] == N
        break
print(*A)

Submission status: Runtime Error

Solution code:
N,K,*A = map(int, open(0).read().split())
n = min(N, len(A))

def left(i, d):
    if not (0 <= i < n):
        return 0
    v = A[i] - d + 0.5
    if v <= 0:
        return 0 + left(i - 1, d + 1)
    else:
        return 1 + left(i - 1, d + 1)

def right(i, d):
    if not (0 <= i < n):
        return 0
    v = A[i] - d + 0.5
    if v <= 0:
        return 0 + right(i + 1, d + 1)
    else:
        return 1 + right(i + 1, d + 1)

for _ in range(K):
    X = [0 for _ in range(n)]
    for i in range(n):
        l = left(i-1, 1)
        r = right(i+1, 1)
        c = 1 + l + r
        X[i] = c
    if A == X:
        print(" ".join(map(str, A)))
        exit(0)
    A = X

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

Submission status: Runtime Error

Solution code:
import numpy as np

N,K=map(int, input().split())
A=np.array(list(map(int, input().split())))
L=np.array([0]*N)
k=0

while  k <K:
	for i in range(N):
		print(i-A[i],i+A[i])
		if i-A[i]>=0 and i+A[i]<=N-1:
			L[i-A[i]:i+A[i]+1]+=1
		elif i-A[i]>=0 and i+A[i]>N-1:
			L[i-A[i]:]+=1
		elif i-A[i]<0 and i+A[i]<=N-1:
			L[:i+A[i]+1]+=1
		else:
			L[:]+=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: Runtime Error

Solution code:
import sys
import math
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
imos = list(map(int, ("0 " + input()).split()))
logn = math.log(n) + 1
# print(logk)
for ii in range(min(k, logn)):
    ans = [0 for _ in range(n + 1)]
    for i in range(1, n + 1):
        left = max(1, i - imos[i])
        # right = min(n, i + imos[i])
        ans[left] += 1
        if i + imos[i] + 1 <= n:
            ans[i + imos[i] + 1] -= 1
    now = 0
    for i in range(len(ans)):
        now += ans[i]
        imos[i] = now

# print(imos)
for i in imos[1:]:
    print(i)

# print(ans)

Submission status: Runtime Error

Solution code:
from numba import njit


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


@njit('(i8[::1],)', cache=True)
def query(lamps):
    counts = [0] * n
    for idx, power in enumerate(lamps):
        start, end = idx - power, idx + power
        if start < 0:
            start = 0
        counts[start] += 1

        if end >= n-1:
            continue
        counts[end+1] -= 1

    now = 0
    for idx, count in enumerate(counts):
        now += count
        lamps[idx] = now


def full_check(counts, full):
    for count in counts:
        if count == full:
            continue
        else:
            return False

    return True


for _ in range(k):
    query(A)
    if full_check(A, n):
        break

print(*A)