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:
### 解答
N, K = map(int, input().split())
A = list(map(int, input().split()))

#B = [0]*N                                 # 記録用のリスト

for k in range(min(42, K)):                        # 以降の操作をK回繰り返す
  B = [0 for _ in range(N)] 
  for i in range(N):                      # 各電球によって照らされる範囲を考える
    start = max(0, i-A[i])                # 始点のインデックスは0かi-A[i]
    end = min(N, i+A[i]+1)                # 終点のインデックスはNかi+A[i]+1
    B[start] += 1                         # 始点に+1を記録する
    if end <= N - 1:
      B[end] -= 1                         # 終点に電球が存在する場合は-1を記録する
  amin = B[0]
  A[0] = B[0] 
  for i in range(1, N):                   # 累積和の計算
    A[i] = B[i-1] + B[i]
    amin = min(A[i], amin)
  if amin == N:                        # すべての電球がN個の電球に照らされるタイミングでbreakする
    break

print(*A)                                 # リストAの中身を順に表示

Submission status: Runtime Error

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

#B = [0]*N                                 # 記録用のリスト

for k in range(K):                        # 以降の操作をK回繰り返す
  B = [0 for _ in range(N)] 
  for i in range(N):                      # 各電球によって照らされる範囲を考える
    start = max(0, i-A[i])                # 始点のインデックスは0かi-A[i]
    end = min(N, i+A[i]+1)                # 終点のインデックスはNかi+A[i]+1
    B[start] += 1                         # 始点に+1を記録する
    if end <= N - 1:
      B[end] -= 1                         # 終点に電球が存在する場合は-1を記録する
  amin = B[0]
  A[0] = B[0] 
  for i in range(1, N):                   # 累積和の計算
    A[i] = B[i-1] + B[i]
    amin = min(A[i], amin)                                   # AをBで更新してつぎのループへ 
  if amin == N:                        # すべての電球がN個の電球に照らされるタイミングでbreakする
    break

print(*A)                                 # リストAの中身を順に表示

Submission status: Runtime Error

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

#B = [0]*N                                 # 記録用のリスト

for k in range(K):                        # 以降の操作をK回繰り返す
  B = [0]*N 
  for i in range(N):                      # 各電球によって照らされる範囲を考える
    start = max(0, i-A[i])                # 始点のインデックスは0かi-A[i]
    end = min(N, i+A[i]+1)                # 終点のインデックスはNかi+A[i]+1
    B[start] += 1                         # 始点に+1を記録する
    if end <= N - 1:
      B[end] -= 1                         # 終点に電球が存在する場合は-1を記録する
  bmin = b[0] 
  for i in range(1, N):                   # 累積和の計算
    B[i] = B[i-1] + B[i]
    bmin = min(B[i], bmin)
  A = B                                   # AをBで更新してつぎのループへ 
  if bmin == N:                        # すべての電球がN個の電球に照らされるタイミングでbreakする
    break

print(*A)                                 # リストAの中身を順に表示

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
B = [0]*N
 
for k in range(K):
 
  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1
 
  for i in range(1, N):
    B[i] = B[i-1] + B[i] 
  A = B
  if min(A) == N:
    break
 
print(*A)

Submission status: Runtime Error

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

B = [0]*N

for k in range(K):

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

  for i in range(1, N):
    B[i] = B[i-1] + B[i] 
  A = B
  if min(A) = N:
    break

print(A)

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import jit

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

def imos(a):
    tmp = np.zeros(n, dtype=np.int64)
    for i in range(n):
        tmp[max(0, i - a[i])] += 1
        print(tmp)
        tmp[min(i + a[i] + 1, n)] -= 1
        print(tmp)
    tmp = np.cumsum(tmp)
    return tmp[:n]
 
for j in range(1, k+1):
    a = imos(a)
print(*a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""

def naive_simulation(N, A_list):
    next_A_list = [0 for i in range(N)]
    for i in range(N):
        d = A_list[i]
        for j in range(i-d, i+d+1):
            if j >= 0 and j <= N-1:
                next_A_list[j] += 1
    A_list = next_A_list[:]
    return A_list

def imos_simulation(N, A_list):
        imos_list = [0 for i in range(N)]
        for i in range(N):
            d = A_list[i]
            imos_list[max(i-d, 0)] += 1
            if i+d+1 <= N-1:
                imos_list[i+d+1] -= 1
        for i in range(1, N):
            imos_list[i] += imos_list[i-1]
        A_list = imos_list[:]
    return A_list

def whole_simulation(N, K, A_list):
    for k in range(min(K, 42)):
        #A_list = naive_simulation(N, A_list)
        A_list = imos_simulation(N, A_list)
        #print(" ".join([ str(i).zfill(2) for i in A_list]))
    return A_list

def main():
    N, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    print(" ".join([ str(i) for i in simulation(N, K, A_list)]))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
light=list(map(int,input().split()))
copy=[0]*N
for k in range(K):
  imo=[0]*(N+1)
  x=0
  for i in range(N):
    kido=light[i]
    imo[max(0,i-kido)]+=1
    imo[min(N-1,i+kido)+1]-=1
  for j in range(N+1):
    x+=imo[j]
    copy[j]=x
  if light==copy:
    break
  else:
    light=copy
print(*light)

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import njit

N, K = map(int, input().split())
A = np.array([int(i) for i in input().split()])

@njit('(i8[::1],)', cache=True)
def solve(A):
    B = np.zeros(N)
    for i, a in enumerate(A):
        l = max(0, i-a)
        r = min(N-1, i+a)
        B[l] += 1
        if r+1<N:
            B[r+1] -= 1
    B = np.cumsum(B)
    return B

for _ in range(min(K, 100)):
    A = solve(A)
print(' '.join(str(int(a)) for a in A))

Submission status: Runtime Error

Solution code:
from numba import njit

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


@njit

def conversion(a):
  b = [0]*(n+1)
  for i in range(n):
    b[max(i-a[i], 0)] += 1
    b[min(i+a[i]+1, n)] -= 1
  a = [0]*n
  for i in range(n):
    a[i] = sum(b[0:i+1])
  return a
 
  

for i in range(min(k, 41)):
  a = conversion(a)

for i in range(n):
  print(a[i], end = ' ')

Submission status: Runtime Error

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


@njit

def conversion(a):
  b = [0]*(n+1)
  for i in range(n):
    b[max(i-a[i], 0)] += 1
    b[min(i+a[i]+1, n)] -= 1
  a = [0]*n
  for i in range(n):
    a[i] = sum(b[0:i+1])
  return a
 
  

for i in range(min(k, 41)):
  a = conversion(a)

for i in range(n):
  print(a[i], end = ' ')

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import njit

@njit
def solve():
    n, k = map(int,input().split())
    l = list(map(int,input().split()))
    
    if k >= 50:
        k = 50
    
    dp= [[0,0]]
    for i in range(n-1):
        dp += [[0]*2]
    
    ans = l[:]
    
    for i in range(k):
        for j in range(n):
            tmp = ans[j]
            dp[j][0] = (j+1 - tmp)
            dp[j][1] = (j+1 + tmp)
    
        ans = [0] * n
    
        for x in range(n):
            for y in range(n):
                if dp[y][0] <= x+1 <= dp[y][1]:
                    ans[x] += 1
    
    else:
        return ans

print(*solve())

Submission status: Runtime Error

Solution code:
from numba import njit

@njit
def solve():
    n, k = map(int,input().split())
    l = list(map(int,input().split()))
    
    if k >= 50:
        k = 50
    
    dp= [[0,0]]
    for i in range(n-1):
        dp += [[0]*2]
    
    ans = l[:]
    
    for i in range(k):
        for j in range(n):
            tmp = ans[j]
            dp[j][0] = (j+1 - tmp)
            dp[j][1] = (j+1 + tmp)
    
        ans = [0] * n
    
        for x in range(n):
            for y in range(n):
                if dp[y][0] <= x+1 <= dp[y][1]:
                    ans[x] += 1
    
    else:
        return ans

print(*solve())

Submission status: Runtime Error

Solution code:
from numba import njit

@njit
def solve():
    n, k = map(int,input().split())
    l = list(map(int,input().split()))
    
    if k >= 50:
        k = 50
    
    dp = [[0] * 2 for i in range(n)]
    
    ans = l[:]
    
    for i in range(k):
        for j in range(n):
            tmp = ans[j]
            dp[j][0] = (j+1 - tmp)
            dp[j][1] = (j+1 + tmp)
    
        ans = [0] * n
    
        for x in range(n):
            for y in range(n):
                if dp[y][0] <= x+1 <= dp[y][1]:
                    ans[x] += 1
    
    else:
        return ans

print(*solve())

Submission status: Runtime Error

Solution code:
from numba import njit

@njit
def solve():
    n, k = map(int,input().split())
    l = list(map(int,input().split()))
    
    if k >= 50:
        k = 50
    
    dp = [[0] * 2 for i in range(n)]
    
    ans = l[:]
    
    for i in range(k):
        for j in range(n):
            tmp = ans[j] + 0.5
            dp[j][0] = (j+1 - tmp)
            dp[j][1] = (j+1 + tmp)
    
        ans = [0] * n
    
        for x in range(n):
            for y in range(n):
                if dp[y][0] <= x+1 <= dp[y][1]:
                    ans[x] += 1
    
    else:
        print(*ans)

solve()

Submission status: Runtime Error

Solution code:
from numba import njit
@njit

def solve():
    n, k = map(int,input().split())
    l = list(map(int,input().split()))
    
    if k >= 50:
        k = 50
    
    dp = [[0] * 2 for i in range(n)]
    
    ans = l[:]
    
    for i in range(k):
        for j in range(n):
            tmp = ans[j] + 0.5
            dp[j][0] = (j+1 - tmp)
            dp[j][1] = (j+1 + tmp)
    
        ans = [0] * n
    
        for x in range(n):
            for y in range(n):
                if dp[y][0] <= x+1 <= dp[y][1]:
                    ans[x] += 1
    
    else:
        print(*ans)

solve()

Submission status: Runtime Error

Solution code:
from numba import njit
@njit

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

if k >= 50:
    k = 50

dp = [[0] * 2 for i in range(n)]

ans = l[:]

for i in range(k):
    for j in range(n):
        tmp = ans[j] + 0.5
        dp[j][0] = (j+1 - tmp)
        dp[j][1] = (j+1 + tmp)

    ans = [0] * n

    for x in range(n):
        for y in range(n):
            if dp[y][0] <= x+1 <= dp[y][1]:
                ans[x] += 1

else:
    print(*ans)

Submission status: Runtime Error

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

for i in range(K):
  Flag = False
  data = [0]*N
  for j in range(N):
    if i-List[i] < 0:
      i-List[i] = 0
    data[i-List[i]] += 1
    if i+List[i]+1 < N:
      data[i+List[i]+1] +=-1
  List[0] = data[0]
  for j in range(N-1):
    List[i+1] = List[i] + data[i+1]
  if List.count(N) == N:
    break
print(*List)

Submission status: Runtime Error

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

if k > (n // 2):
    for j in range(n):
        print(n,end = " ");
        
else:
    #累積和数列にぶち込む
    for i in range(n-1):
        a[i+1] += a[i];

    for i in range(k):
        b = [0]*n;
        for p in range(0,a[0]+1):
            b[p] += 1;
        
        for q in range(1,n):
            for r in range(max(0,q-a[q]+a[q-1]),min(n,q+a[q]-a[q-1]+1)):
                b[r] += 1;
        
        a[0] = b[0];
        for s in range(1,n):
            a[s] = a[s-1] + b[s];
        
    print(a[0],end = " ")
    for j in range(1,n):
        print(a[j]-a[j-1],end = " ");

Submission status: Runtime Error

Solution code:
buf = list(map(int, input().split()))
N=buf[0]
K=buf[1]
A = list(map(int, input().split()))
B=[0]*len(A)

for k in range(K):
  for a in range(len(A)):
    for i in range(a-A[a],a+A[a]+1):
      B[i]=B[i]+1
  A=B
print(" ".join([str(a) for a in A]))

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import njit


@njit
def get_a(n, k, a):
    for _ in range(k):
        B = np.zeros((n + 1), dtype=np.int64)
        for i in range(n):
            l = max(0, i - a[i])
            r = min(n - 1, i + a[i])
            B[l] += 1
            if r + 1 < n:
                B[r + 1] -= 1

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

        a = B[:-1]

    print(a)


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    get_a(N, K, A)

Submission status: Runtime Error

Solution code:
import sys
n, k = map(int, sys.stdin.readline().rstrip().split())
an = list(map(int, sys.stdin.readline().rstrip().split()))

import numpy as np

t= min(k, 45)

for i in range(t):
    bn = np.zeros(n)
    for i in range(n):
        bn[max(i - an[i], 0)] += 1

        if i+ an[i]+1 <n:
            bn[i+an[i]+1] -=1
    an = np.cumsum(bn)

an = [int(i) for i in an]
print(*an)

Submission status: Runtime Error

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

ruiseki=np.arange(N)
y=np.zeros(N) 
for i in range(K):
    r=0
    for j in range(N):
        num=A[j]
        y[max([j-num,0])]-=ruiseki[max([j-num,0])]*ruiseki[max([j-num,0])]
        y[min([j+num+1,N])]+=ruiseki[min([j+num+1,N])]*ruiseki[min([j+num+1,N])]
    
print(' '.join(map(str, y)))

Submission status: Runtime Error

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

for h in range(N):
    L.append(0)

for i in range(K):
    
    for j in range(N):
        
        for k in range(A[j] * 2 + 1):
            
            try:    
                if ((k - A[j] + j) >= 0):
                    L[k - A[j] + j] += 1
            
            except IndexError:
                pass
   
    A = copy.copy(L)
    L = []
    
    for h in range(N):
        L.append(0)

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

Submission status: Runtime Error

Solution code:
import copy

N_K = input().split(" ")
A = input().split(" ")
A = [int(s) for s in A]
N = int(N_K[0])
K = int(N_K[1])
L = [0, 0, 0, 0, 0]
for i in range(K):
    for j in range(N):
        for k in range(A[j] * 2 + 1):
            try:    
                if ((k - A[j] + j) >= 0):
                    L[k - A[j] + j] += 1
            except IndexError:
                pass
    A = copy.copy(L)
    L = [0, 0, 0, 0, 0]
A = [str(t) for t in A]
print(" ".join(A))

Submission status: Runtime Error

Solution code:
import copy

N_K = input().split(" ")
A = input().split(" ")
A = [int(s) for s in A]
N = int(N_K[0])
K = int(N_K[1])
L = [0, 0, 0, 0, 0]
for i in range(K):
    for j in range(N):
        for k in range(A[j] * 2 + 1):
            try:    
                if ((k - A[j] + j) >= 0):
                    L[k - A[j] + j] += 1
            except IndexError:
                pass
    A = copy.copy(L)
print(L)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    vs=[]
    ws=[]
    costs=tuple(tuple(map(int, input().split())) for i in range(N))
    visited=[0]*N
    Q=int(input())
    qs= tuple(tuple(map(int, input().split())) for i in range(Q))
    maxL=int(max([qs[i][1] for i in range(Q)]))

    
        
    for v,L in qs:
        if v==1:
            v,w=costs[1]
            if w<=L:print(v)
            else:print(0)
            continue

        n=[]
        while v:
            n.append(costs[v-1])
            v=v//2
        ln=len(n)
        n1=n[:ln//2]
        n2=n[ln//2:]
        
        n1c=[]
        n2c=[]
        for i in range(len(n1)+1):
            for n1b in combinations(n1,i):
                vsum=sum([x[0] for x in n1b])
                wsum=sum([x[1] for x in n1b])
                n1c.append((wsum,vsum))
        for i in range(len(n2)+1):
            for n2b in combinations(n2,i):
                vsum=sum([x[0] for x in n2b])
                wsum=sum([x[1] for x in n2b])
                n2c.append((wsum,vsum))
        vmax=10**5+1
        n1c.sort(key=lambda k: k[0]*vmax+k[1])
        n2c.sort(key=lambda k: k[0]*vmax+k[1])
        
        j1=1
        for i in range(1,len(n1c)):
            if n1c[i][1]>n1c[j1-1][1]:
                n1c[j1]=n1c[i]
                j1+=1
        
        j2=1
        for i in range(1,len(n2c)):
            if n2c[i][1]>n2c[j2-1][1]:
                n2c[j2]=n2c[i]
                j2+=1

        j=j1-1
        ans=0
        for i in range(j2):
            w,v=n2c[i]
            while n1c[j][0]+w>L and j>=0:
                j-=1
            if j==-1:
                break
            ans=max(ans,v+n1c[j][1])
        print(ans)







if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
B =[]
for i in range(N):
	B.append(0)
for p in range(K):
	for i in range(N):
		for j in range(1 +A[i]):
			if j == 0:
				B[i] +=  1
			else:
				if i - j>= 0:
					B[i-j] += 1
				if i + j < N:
					B[i+j] += 1
	if min(B)+(k-p)=>N:
		for i in range(N):
			A[i] =N
		break        
    for i in range(N):
		A[i] =B[i]
		B[i] = 0
print(A)

Submission status: Runtime Error

Solution code:

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

    l_chk=[0] * N
    cnt = 0
    for i in range(K):

        for j in range(N):
            cnt = 0
            for k in range(N):
                if A[j] == N:
                    break
                if j == k:
                    cnt = cnt + 1
                elif abs(k-j) <= A[k]:
                    cnt = cnt + 1
            l_chk[j] = cnt
        for j in range(N):
            A[j] = l_chk[j]


    print(*A)

OK()

Submission status: Runtime Error

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

A_list = np.array([0]+list(map(int, input().split())))
#print(A_np)


for j in range(min(K,46):
  new_A=np.zeros(N+2,dtype=np.int64)
  for i in range(1,N+1):
    #print(new_A)
    mi=i-A_list[i]
    ma=i+A_list[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #new_A[mi:ma+1]+=1
    new_A[mi]+=1
    new_A[ma+1]-=1

  A_list=np.cumsum(new_A)
  #if A_list[1:N+1])==N*N:
  #  break
    
for i in range(1,N+1):
  print(A_list[i],end=" ")

Submission status: Runtime Error

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

A_list = np.array([0]+list(map(int, input().split())))
#print(A_np)

new_A=np.array([0]*(N+2))
for j in range(1):
  for i in range(1,N+1):
    print(new_A)
    mi=i-A_list[i]
    ma=i+A_list[i]
    if mi<0:
      mi=0
    if ma>N+1:
      ma=N+1
    #new_A[mi:ma+1]+=1
    new_A[mi]+=1
    new_A[ma+1]-=1

  A_list=np.cumsum(new_A)
  if sum(A_list[1:N+1])==N*N:
    break
    
for i in range(1,N+1):
  print(A_list[i],end=" ")

Submission status: Runtime Error

Solution code:
N,k = map(int,input().split())
a_l = [int(a) for a in input().split()]
for _ in range(min(k,41)):
    a = [0] * (N+1)
    for i,x in enumerate(a_l):
        a[max(0,i-x)] += 1
        a[min(i+x+1,N)] -= 1
    a_l = np.cumsum(np.array(a))[:-1].tolist()
print(' '.join(map(str, a_l)))

Submission status: Runtime Error

Solution code:
import numpy as np

N,k = map(int,input().split())
l = [int(a) for a in input().split()]
for _ in range(min(k,41)):
    a = [0] * (N+1)
    for i,x in enumerate(a_l):
        a[max(0,i-x)] += 1
        a[min(i+x+1,N)] -= 1
    a_l = np.cumsum(np.array(a))[:-1].tolist()
print(' '.join(map(str, a_l)))

Submission status: Runtime Error

Solution code:
import numpy
N, K = map(int, input().split())
A = [i for i in map(int, input().split())]
table = numpy.zeros([K+1, N], dtype = int)
table[0] = A
for k in range(K):
    for n in range(N):
        table[k+1][max(0, n-table[k][n]):min(N, n+table[k][n])+1]+= 1
ans = ""
for n in range(N):
    ans+=str(table[K,n])+" "
print(ans)

Submission status: Runtime Error

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

ans1=[0]*n

for b in range(0,n):
  temp=ans[b]
    
  d=b-temp
  if d <= 0:
    d=0
  e=b+temp
  if e >= n-1:
    e=n-1
  for c in range(d,e+1):
    ans1[c]=ans1[c]+1
    

    
for a in range(0,k-1):
  ans2=ans1
  ans3=[0]*n
  for b in range(0,n):
  	temp=ans1[b]
    
  	d=b-temp
  	if d <= 0:
    	 d=0
  	e=b+temp
  	if e >= n-1:
    	 e=n-1
  	for c in range(d,e+1):
    	 ans3[c]=ans3[c]+1
  ans1=ans3
  if ans1.count(n)==n:
    break
  


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

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import jit

@jit('i2[:](i2,i2,i2[:])',cashe=True)
def solve(n,k,A):
    l,r=0,0
    for i in range(k):
        B=np.zeros(n+1,dtype=np.int64)
        for x,y in enumerate(list(A)):
            l=max(0,x-y)
            r=min(n,x+y+1)
            B[l]+=1
            B[r]-=1
        A=np.cumsum(B[:-1])
        if A[A==n].size==n:
            break
    return A
n,k=map(int,input().split())
a=list(map(int,input().split()))
A=np.array(a)
X=solve(n,k,A)
print(*X,sep=' ')

Submission status: Runtime Error

Solution code:
import numpy as np
import numba
from numba import jit, njit, prange
# -- numba (jit compile) ------------
# @njit

@jit
def calc(x, zero, BB):
    for j in range(1, x + 1):
        pp = BB[j - 1]

        if (pp == 0):
            zero[int(j - 1)] += 1
            # print(d)
            continue
        if (pp == x):
            zero += 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 > x - 1):
            right = x
        #print('L&R: ', left, right)

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

    return zero


# ---- read ---------------------------------
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)
# --- main ----------------------------
for i in range(k):
    #d = [0] * n
    # print(i)
    d = np.zeros(n, dtype=np.int64)
    d = calc(n, d, bb)
    bb = d

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

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

Submission status: Runtime Error

Solution code:
import math

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

b = [0]*n

for i in range(n):
    i0 = i+1
    if i0 - a0[i] - 0.5 < 1:
        amin = 1
    else:
        amin = math.ceil(i0 - a0[i] - 0.5)
    if i0 + a0[i] + 0.5 > n:
        amax = n
    else:
        amax = math.floor(i0 + a0[i] + 0.5)
    amin = int(amin)
    amax = int(amax)
    for j in range(amin-1,amax):
        b[j] += 1

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

for i in range(n):
    a[0][i] = a0[i] 

for i in range(1,41):
    for j in range(n):
        a[i][j] = b[j]
    b=[0]*n
    for j in range(n):
        j0 = j+1
        if j0 - a[i][j] - 0.5 < 1:
            amin = 1
        else:
            amin = math.ceil(j0 - a[i][j] - 0.5)
        if j0 + a[i][j] + 0.5 > n:
            amax = n
        else:
            amax = math.floor(j0 + a[i][j] + 0.5)
        amin = int(amin)
        amax = int(amax)
        for l in range(amin-1,amax):
            b[l] += 1

aa = [0]*n
for i in range(n):
    aa[i] = str(a[k][i])

print(' '.join(aa))

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N,K=map(int,input().split())
A=list(map(int,input().split()))
imos=[0 for i in range(N+1)]
ANS=[str(N)]*N
@njit(cache = True) 
if K>=40:
  ans=" ".join(ANS)
  print(ans)
else:
  for t in range(K):
    for i in range(N):
      l=max(0,i-A[i])
      r=min(N,i+A[i]+1)
      imos[l]+=1
      imos[r]-=1
    imos=list(accumulate(imos))
    for i in range(0,N):
      A[i]=imos[i]
    imos=[0 for i in range(N+1)]
  for i in range(N):
    A[i]=str(A[i])
  ans=" ".join(A)
  print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N,K=map(int,input().split())
A=list(map(int,input().split()))
imos=[0 for i in range(N+1)]
ANS=[str(N)]*N
if K>=40:
  ans=" ".join(ANS)
  print(ans)
else:
  for t in range(K):
    for i in range(N):
      l=max(0,i-A[i])
      r=min(N,i+A[i]+1)
      imos[l]+=1
      imos[r]-=1
    imos=lisT(accumulate(imos))
    for i in range(0,N):
      A[i]=imos[i]
    imos=[0 for i in range(N+1)]
  for i in range(N):
    A[i]=str(A[i])
  ans=" ".join(A)
  print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N,K=map(int,input().split())
A=list(map(int,input().split()))
imos=[0 for i in range(N+1)]
ANS=[str(N)]*N
if K>=50:
  ans=" ".join(ANS)
  print(ans)
else:
  for t in range(K):
    for i in range(N):
      l=max(0,i-A[i])
      r=min(N,i+A[i]+1)
      imos[l]+=1
      imos[r]-=1
    imos=accumulate(imos)
    for i in range(0,N):
      A[i]=imos[i]
    imos=[0 for i in range(N+1)]
  for i in range(N):
    A[i]=str(A[i])
  ans=" ".join(A)
  print(ans)

Submission status: Runtime Error

Solution code:

import numpy as np
def resolve():

    N, K = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)

    for _ in range(K):
        imos_table = np.zeros(N+1, dtype=np.int64)
        for i, a in enumerate(A):
            # 配列の個数を超えないように注意
            imos_table[max(i - a, 0)] += 1
            imos_table[min(i + a + 1, N)] -= 1
        A = np.cumsum(imos_table)[:-1]
        if np.all(A == N):
            print(*A)
            return
    else:
        print(*A)

if __name__ == "__main__":
    resolve()