input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
from decimal import * a, b, c = list(map(int, input().split())) if Decimal(a)**Decimal("0.5") + Decimal(b)**Decimal("0.5") < Decimal( c)**Decimal("0.5"): print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) # a + 2√ab + b < c , 2√ab < c - a - b, 4ab < (c - a - b)^2 if c - a - b < 0: print("No") else: print(("Yes" if 4 * a * b < (c - a - b)**2 else "No"))
p02743
# -*- coding: utf-8 -*- import sys import math from bisect import bisect_left from bisect import bisect_right import collections import copy import heapq from collections import defaultdict from heapq import heappop, heappush import itertools input = sys.stdin.readline from decimal import * ##### リストの 二分木検索 ##### # bisect_left(lists, 3) # bisect_right(lists, 3) ##### プライオリティキュー ##### # heapq.heapify(a) #リストaのheap化 # heapq.heappush(a,x) #heap化されたリストaに要素xを追加 # heapq.heappop(a) #heap化されたリストaから最小値を削除&その最小値を出力 # heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう # heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと ##### タプルリストのソート ##### # sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順 # sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順 # sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順 # sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順 # sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順 # sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順 ##### 累乗 ##### # pow(x, y, z) -> x**y % z def inputInt(): return int(eval(input())) def inputMap(): return list(map(int, input().split())) def inputList(): return list(map(int, input().split())) inf = float('inf') mod = 1000000007 #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- def main(): a,b,c = inputMap() getcontext().prec = 50000 #print(Decimal(a).sqrt()) #if c == a or c == b: #print("No") #sys.exit() if Decimal(Decimal(a).sqrt() + Decimal(b).sqrt()) < Decimal(c).sqrt(): print("Yes") else: print("No") #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- # special thanks : # https://nagiss.hateblo.jp/entry/2019/07/01/185421 #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- def int_sqrt2(n): def f(prev): while True: m = (prev + n / prev) / 2 if m >= prev: return prev prev = m return f(int(math.sqrt(n) * (1 + 1e-10))) # nCr mod m # rがn/2に近いと非常に重くなる def combination(n, r, mod=10**9+7): r = min(r, n-r) res = 1 for i in range(r): res = res * (n - i) * modinv(i+1, mod) % mod return res # mを法とするaの乗法的逆元 def modinv(a, mod=10**9+7): return pow(a, mod-2, mod) def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - (b // a) * y, y # nHr mod m # 問題によって、combination()を切り替えること def H(n, r, mod=10**9+7): # comb = Combination(n+r-1, mod) # return comb(n+r-1, r) return combination(n+r-1, r, mod) class Combination: """ O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms) 使用例: comb = Combination(1000000) print(comb(5, 3)) # 10 """ def __init__(self, n_max, mod=10**9+7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n+1): fac.append(fac[i-1] * i % self.mod) facinv.append(facinv[i-1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n+1) modinv[1] = 1 for i in range(2, n+1): modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod return modinv if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import math from bisect import bisect_left from bisect import bisect_right import collections import copy import heapq from collections import defaultdict from heapq import heappop, heappush import itertools input = sys.stdin.readline from decimal import * ##### リストの 二分木検索 ##### # bisect_left(lists, 3) # bisect_right(lists, 3) ##### プライオリティキュー ##### # heapq.heapify(a) #リストaのheap化 # heapq.heappush(a,x) #heap化されたリストaに要素xを追加 # heapq.heappop(a) #heap化されたリストaから最小値を削除&その最小値を出力 # heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう # heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと ##### タプルリストのソート ##### # sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順 # sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順 # sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順 # sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順 # sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順 # sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順 ##### 累乗 ##### # pow(x, y, z) -> x**y % z def inputInt(): return int(eval(input())) def inputMap(): return list(map(int, input().split())) def inputList(): return list(map(int, input().split())) inf = float('inf') mod = 1000000007 #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- def main(): a,b,c = inputMap() getcontext().prec = 20007 #print(Decimal(a).sqrt()) #if c == a or c == b: #print("No") #sys.exit() if Decimal(Decimal(a).sqrt() + Decimal(b).sqrt()) < Decimal(c).sqrt(): print("Yes") else: print("No") #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- # special thanks : # https://nagiss.hateblo.jp/entry/2019/07/01/185421 #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- def int_sqrt2(n): def f(prev): while True: m = (prev + n / prev) / 2 if m >= prev: return prev prev = m return f(int(math.sqrt(n) * (1 + 1e-10))) # nCr mod m # rがn/2に近いと非常に重くなる def combination(n, r, mod=10**9+7): r = min(r, n-r) res = 1 for i in range(r): res = res * (n - i) * modinv(i+1, mod) % mod return res # mを法とするaの乗法的逆元 def modinv(a, mod=10**9+7): return pow(a, mod-2, mod) def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - (b // a) * y, y # nHr mod m # 問題によって、combination()を切り替えること def H(n, r, mod=10**9+7): # comb = Combination(n+r-1, mod) # return comb(n+r-1, r) return combination(n+r-1, r, mod) class Combination: """ O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms) 使用例: comb = Combination(1000000) print(comb(5, 3)) # 10 """ def __init__(self, n_max, mod=10**9+7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n+1): fac.append(fac[i-1] * i % self.mod) facinv.append(facinv[i-1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n+1) modinv[1] = 1 for i in range(2, n+1): modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod return modinv if __name__ == "__main__": main()
p02743
import decimal a,b,c=list(map(int,input().split())) print((["No","Yes"][decimal.Decimal(a).sqrt()+decimal.Decimal(b).sqrt()<decimal.Decimal(c).sqrt()]))
a,b,c=list(map(int,input().split())) print((["No","Yes"][4*a*b<(c-a-b)**2 and c-a-b>0]))
p02743
from decimal import Decimal a, b, c = list(map(int,input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No")
import math a, b, c = list(map(int, input().split())) ab = a * b out = c - a - b num = ((out))**2 if out < 0: num = -num if 4*ab < num: print("Yes") else: print("No")
p02743
from decimal import Decimal def main(): a,b,c = list(map(int, input().split(" "))) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print('Yes') else: print('No') main()
def main(): a,b,c = list(map(int, input().split(" "))) if (4 * a * b) < (c - a - b) * (c - a - b) and (c - a - b) > 0: print('Yes') else: print('No') main()
p02743
from math import sqrt from decimal import * a, b, c = list(map(int, input().split())) """ print(sqrt(a), sqrt(b)) print(Decimal(sqrt(a)), sqrt(b)) """ print(("Yes" if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt() else "No"))
from math import sqrt a, b, c = list(map(int, input().split())) print(("Yes" if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0 else "No"))
p02743
from decimal import * getcontext().prec = 40000 a, b, c = list(map(int, input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No")
from decimal import * getcontext().prec = 30000 a, b, c = list(map(int, input().split())) # if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): if a + b + 2 * Decimal(a * b).sqrt() < c: print("Yes") else: print("No")
p02743
a, b, c = list(map(int, input().split())) # print(a ** 0.5, b ** 0.5, c ** 0.5) digit = 5000 right = (c - a - b) * (10 ** digit) ab = a * b * (10 ** (digit * 2)) sqrt_ab = 0 ans = False for i in range(10 ** 5): # print(i, i * i * (10 ** (digit * 2)), ab, (i - 1) * (10 ** digit)) if i * i * (10 ** (digit * 2)) > ab: sqrt_ab += (i - 1) * (10 ** digit) break # print(sqrt_ab) for i in range(1, digit): # if int(sqrt_ab + 1) * 2 < right: # ans = True # break for j in range(1, 10): # print(i, j, sqrt_ab + j * (10 ** (digit - i)), ) if (sqrt_ab + j * (10 ** (digit - i))) ** 2 > ab: sqrt_ab += (j - 1) * (10 ** (digit - i)) break elif j == 9: sqrt_ab += j * (10 ** (digit - i)) break if 2 * sqrt_ab < right: print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if c - a - b > 0 and 4 * a * b < ((c - a - b) ** 2): print("Yes") else: print("No")
p02743
a, b, c = list(map(int, input().rstrip().split())) from decimal import * getcontext().prec = 100000 if (Decimal(a).sqrt() + Decimal(b).sqrt()) < Decimal(c).sqrt(): print('Yes') else: print('No')
a, b, c = list(map(int, input().rstrip().split())) from decimal import * getcontext().prec = 500 if (Decimal(a).sqrt() + Decimal(b).sqrt()) < Decimal(c).sqrt(): print('Yes') else: print('No')
p02743
from decimal import * getcontext().prec = 100000 a, b, c = list(map(int, input().split())) #print(a **.5, b**.5,c**.5) #print(a **.5+ b**.5,c**.5) #print(Decimal(a).sqrt() , Decimal(b).sqrt() , Decimal(c).sqrt()) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): #if a **.5 + b**.5 < c**.5: print('Yes') else: print('No')
from decimal import * getcontext().prec = 40000 a, b, c = list(map(int, input().split())) #print(a **.5, b**.5,c**.5) #print(a **.5+ b**.5,c**.5) #print(Decimal(a).sqrt() , Decimal(b).sqrt() , Decimal(c).sqrt()) if Decimal(a).sqrt() + Decimal(b).sqrt() >= Decimal(c).sqrt(): #if a **.5 + b**.5 < c**.5: print('No') else: print('Yes')
p02743
from decimal import * getcontext().prec = 40000 a, b, c = list(map(int, input().split())) #print(a **.5, b**.5,c**.5) #print(a **.5+ b**.5,c**.5) #print(Decimal(a).sqrt() , Decimal(b).sqrt() , Decimal(c).sqrt()) if Decimal(a).sqrt() + Decimal(b).sqrt() >= Decimal(c).sqrt(): #if a **.5 + b**.5 < c**.5: print('No') else: print('Yes')
from decimal import * getcontext().prec = 30000 a, b, c = list(map(int, input().split())) #print(a **.5, b**.5,c**.5) #print(a **.5+ b**.5,c**.5) #print(Decimal(a).sqrt() , Decimal(b).sqrt() , Decimal(c).sqrt()) #if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): if 2 * Decimal(a * b).sqrt() + Decimal(b) + Decimal(a) < Decimal(c): #if a **.5 + b**.5 < c**.5: print('Yes') else: print('No')
p02743
def main(): from decimal import Decimal a, b, c = list(map(int, input().split())) x = Decimal(a).sqrt() y = Decimal(b).sqrt() z = Decimal(c).sqrt() print(('Yes' if x + y < z else 'No')) if __name__ == '__main__': main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
def main(): a, b, c = list(map(int, input().split())) if c - a - b < 0: print('No') return res = 'Yes' if 4 * a * b < (c - a - b) * (c - a - b) else 'No' print(res) if __name__ == '__main__': main()
p02743
import math from decimal import * # getcontext().prec = 300 a,b,c = list(map(int,input().split())) if Decimal(a)**Decimal('0.5') + Decimal(b)**Decimal('0.5') < Decimal(c)**Decimal('0.5'): print("Yes") else: print("No")
import math from decimal import * # getcontext().prec = 300 a,b,c = list(map(int,input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No")
p02743
from decimal import Decimal a,b,c=list(map(int,input().split())) ab_=Decimal(a).sqrt()+Decimal(b).sqrt() c_=Decimal(c).sqrt() if ab_<c_: print('Yes') else: print('No')
a,b,c=list(map(int,input().split())) if c-a-b>0 and 4*a*b<(c-a-b)**2: print('Yes') else: print('No')
p02743
from decimal import * getcontext().prec = 20000 a, b, c = [Decimal(int(i)) for i in input().split()] if a.sqrt() + b.sqrt()-c.sqrt() < Decimal("-0."+"0"*10000+"1"): print("Yes") else: print("No")
from decimal import * a, b, c = [Decimal(int(i)) for i in input().split()] if a.sqrt() + b.sqrt()-c.sqrt() < Decimal("-0."+"0"*20+"1"): print("Yes") else: print("No")
p02743
from decimal import Decimal a,b,c=list(map(int,input().split())) if Decimal(a)**Decimal('0.5')+Decimal(b)**Decimal('0.5')<Decimal(c)**Decimal('0.5'): print('Yes') else: print('No')
import decimal a,b,c=list(map(int,input().split())) if decimal.Decimal(a)**decimal.Decimal('0.5')+decimal.Decimal(b)**decimal.Decimal('0.5')<decimal.Decimal(c)**decimal.Decimal('0.5'): print('Yes') else: print('No')
p02743
# -*- coding: utf-8 -*- import sys from decimal import Decimal def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 EPS = 10 ** -14 a, b, c = MAP() if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): Yes() else: No()
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 a, b, c = MAP() if c-a-b >= 0 and 4*a*b < pow(c-a-b, 2): Yes() else: No()
p02743
from decimal import Decimal a,b,c=list(map(int,input().split())) print(("Yes" if Decimal(a).sqrt()+Decimal(b).sqrt()<Decimal(c).sqrt() else "No"))
a,b,c=list(map(int,input().split())) print(("Yes" if c-a-b>0 and 4*a*b<(c-a-b)**2 else "No"))
p02743
from decimal import * def resolve(): a, b, c = list(map(int, input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No") resolve()
def resolve(): a, b, c = list(map(int, input().split())) if c-a-b>0 and (c-a-b)**2 > 4*a*b: print("Yes") else: print("No") resolve()
p02743
from decimal import Decimal #decimal.Decimalってしなくて済むよ a,b,c = list(map(int,input().split())) a = a ** Decimal("0.5") b = b ** Decimal("0.5") c = c ** Decimal("0.5") a_b = a + b if c > a_b: print("Yes") else: print("No")
from decimal import Decimal #decimal.Decimalってしなくて済むよ a,b,c = list(map(int,input().split())) a = a ** Decimal(0.5) b = b ** Decimal(0.5) c = c ** Decimal(0.5) a_b = a + b if c > a_b: print("Yes") else: print("No")
p02743
from decimal import Decimal, getcontext a,b,c = input().split() getcontext().prec = 10000 a = Decimal(a).sqrt() b = Decimal(b).sqrt() c = Decimal(c).sqrt() if a+b+Decimal(1e-14)< c: print("Yes") else: print("No")
from decimal import Decimal, getcontext a,b,c = input().split() getcontext().prec = 65 a = Decimal(a).sqrt() b = Decimal(b).sqrt() c = Decimal(c).sqrt() if a+b < c: print("Yes") else: print("No")
p02743
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): a,b,c = list(map(int, readline().split())) if c > a + b: if c**2 + a**2 + b**2 - 2*a*c - 2*b*c + 2*a*b > 4*a*b: print("Yes") else: print("No") else: print("No") if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): a,b,c = list(map(int, readline().split())) if c - a - b > 0 and (c - a - b)**2 > 4*a*b: print("Yes") else: print("No") if __name__ == "__main__": main()
p02743
a,b,c=list(map(int,input().split())) print(("Yes"if(a-b-c)**2-4*b*c>0and c-a-b>0else"No"))
a,b,c=list(map(int,input().split())) print((["No","Yes"][(a-b-c)**2-4*b*c>0and c-a-b>0]))
p02743
a,b,c=list(map(int,input().split())) print((["No","Yes"][(a-b-c)**2-4*b*c>0and c-a-b>0]))
a,b,c=list(map(int,input().split())) print((["No","Yes"][(a-b-c)**2>4*b*c and c-a>b]))
p02743
from decimal import * a,b,c = list(map(int,input().split())) getcontext().prec = 50 if Decimal(a)**Decimal(0.5) + Decimal(b)**Decimal(0.5) < Decimal(c)**Decimal(0.5): ans = "Yes" else: ans = "No" print(ans)
a,b,c = list(map(int,input().split())) if c-a-b > 0 and (c-a-b)**2 > 4*a*b: ans = "Yes" else: ans = "No" print(ans)
p02743
from decimal import Decimal a, b, c = list(map(int,input().split())) if (Decimal(a).sqrt() + Decimal(b).sqrt()) >= Decimal(c).sqrt(): print('No') else: print('Yes')
a,b,c = list(map(int, input().split())) if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0: print('Yes') else: print('No')
p02743
from decimal import Decimal import math a,b,c=list(map(int,input().split())) if c-a-b>0 and 4*a*b<(c-a-b)**2: print("Yes") else: print("No")
a,b,c=list(map(int,input().split())) if 4*a*b < (c-a-b)**2 and (c-a-b)>0: print("Yes") else: print("No")
p02743
from decimal import * import math #getcontext().prec=100 a,b,c=list(map(int,input().split())) if a+b+2*Decimal(a*b).sqrt()<c: print("Yes") else: print("No")
a, b, c = list(map(int,input().split())) from decimal import * getcontext().prec = 100 if (a + b + 2*(Decimal(a).sqrt())*(Decimal(b).sqrt()) < c): print('Yes') else: print('No')
p02743
from decimal import * import math getcontext().prec=100000 a,b,c=list(map(int,input().split())) if Decimal(a).sqrt()+Decimal(b).sqrt()<Decimal(c).sqrt(): print("Yes") else: print("No")
from decimal import * import math #getcontext().prec=10000 a,b,c=list(map(int,input().split())) if Decimal(a).sqrt()+Decimal(b).sqrt()<Decimal(c).sqrt(): print("Yes") else: print("No")
p02743
import math square_list = [i**2 for i in range(1, 10**5)] def integer_squareroot(x): imin = 0 imax = x while imin <= imax: imid = (imin + imax) // 2 imid_squared = imid ** 2 if imid_squared <= x: imin = imid + 1 else: imax = imid - 1 return imin - 1 a, b, c = list(map(int, input().split())) if 4 * a * b < (c-a-b) ** 2 and c - a - b > 0: print("Yes") else: print("No") # for i in range(3): # if A[i] in square_list: # A[i] = integer_squareroot(A[i]) # else: # A[i] = math.sqrt(A[i]) # if A[0] + A[1] + 1e-11 < A[2]: # print("Yes") # elif A[0] + A[1] < A[2]: # print("Yes") # else: # print("No")
from decimal import Decimal a, b, c = map(Decimal, input().split()) cond = a.sqrt() + b.sqrt() < c.sqrt() print("Yes") if cond else print("No")
p02743
from decimal import * getcontext().prec = 7000 #import numpy as np a, b, c = list(map(float, input().split())) ##print(a**0.5, b**0.5, c**0.5) if Decimal(a).sqrt()+ Decimal(b).sqrt() < Decimal(c).sqrt(): print('Yes') else: print('No')
a, b, c = list(map(int, input().split())) if c < (a+b): print('No') elif 4*a*b < (c-a-b)**2: print('Yes') else: print('No')
p02743
from decimal import Decimal, getcontext getcontext().prec = 1000 a, b, c = list(map(Decimal, input().split())) print(("Yes" if a+b+Decimal(2)*((a*b)**Decimal(0.5)) < c else "No"))
a, b, c = list(map(int, input().split())) if c-a-b < 0: print("No") else: print(("Yes" if (c-a-b)**2-4*a*b > 0 else "No"))
p02743
from decimal import * getcontext().prec = 128 a, b, c = [int(i) for i in input().split()] print(("Yes" if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt() else "No"))
a, b, c = [int(i) for i in input().split()] d = c - a - b print(('Yes' if d > 0 and d**2 > 4*a*b else 'No'))
p02743
from decimal import * getcontext().prec = 20 # デフォルト28桁のところを20桁にする a, b, c = list(map(int, input().split())) A = Decimal(a).sqrt() B = Decimal(b).sqrt() C = Decimal(c).sqrt() if A+B < C: print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if c - a - b >= 0 and 4*(a*b) < (c - a - b)**2: print("Yes") else: print("No")
p02743
import sys input = lambda: sys.stdin.readline().rstrip() from decimal import * a,b,c = list(map(int, input().split())) a = Decimal(a).sqrt() b = Decimal(b).sqrt() c = Decimal(c).sqrt() if a + b < c: print("Yes") else: print("No")
import sys input = lambda: sys.stdin.readline().rstrip() a,b,c = list(map(int, input().split())) if c - a - b < 0: print("No") elif 4 * a * b < (c - a - b) ** 2: print('Yes') else: print('No')
p02743
from decimal import Decimal a, b, c = list(map(int, input().split())) a = Decimal(a).sqrt() b = Decimal(b).sqrt() c = Decimal(c).sqrt() if a + b < c: print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) print(("Yes" if ((c-a-b) > 0 and 4*a*b < (c-a-b)**2) else "No"))
p02743
a, b, c = list(map(int, input().split())) from decimal import Decimal if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print('Yes') else: print('No')
a,b,c = list(map(int, input().split())) if 4*a*b < (c-a-b)**2 and c-a-b > 0: print('Yes') else: print('No')
p02743
import sys import re import math import collections import decimal import bisect # import copy # import heapq # from collections import deque # import decimal # sys.setrecursionlimit(100001) INF = sys.maxsize # MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: list(map(int, sys.stdin.readline().split())) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): a, b, c = ns() tmp = decimal.Decimal(a).sqrt() + decimal.Decimal(b).sqrt() - decimal.Decimal(c).sqrt() print(("Yes" if tmp < 0 else "No")) if __name__ == '__main__': main()
import sys import re import math import collections import decimal import bisect # import copy # import heapq # from collections import deque # import decimal # sys.setrecursionlimit(100001) INF = sys.maxsize # MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: list(map(int, sys.stdin.readline().split())) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): a, b, c = ns() flg = a**2+b**2+c**2-2*a*b-2*a*c-2*b*c>0 and -a - b + c > 0 print(("Yes" if flg else "No")) if __name__ == '__main__': main()
p02743
from decimal import Decimal a,b,c=list(map(int,input().split())) if(Decimal(a).sqrt()+Decimal(b).sqrt()<Decimal(c).sqrt()): print("Yes") else: print("No")
a,b,c=list(map(int,input().split())) print(("Yes" if 4*a*b<(c-a-b)**2 and c-a-b>0 else "No"))
p02743
from decimal import Decimal a, b, c = [int(i) for i in input().strip().split()] if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No")
import sys input = sys.stdin.readline def main(): a, b, c = list(map(int, input().split())) y = (c - (a+b))**2 - 4*a*b if c-(a+b) > 0 and y > 0: print("Yes") else: print("No") if __name__ == "__main__": main()
p02743
from decimal import * getcontext().prec = 100000 a, b, c = list(map(int, input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print('Yes') else: print('No')
from decimal import * getcontext().prec = 50 a, b, c = list(map(int, input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print('Yes') else: print('No')
p02743
from decimal import * getcontext().prec=3000 a,b,c=list(map(int,input().split())) print(('Yes' if Decimal(a)**Decimal(0.5)+Decimal(b)**Decimal(0.5)<Decimal(c)**Decimal(0.5) else 'No'))
a,b,c=list(map(int,input().split())) print(('Yes' if c-a-b>0 and 4*a*b<(c-a-b)**2 else 'No'))
p02743
a,b,c = list(map(int,input().split())) if c-(a+b) < 0: print('No') else: if 4*a*b < (c-(a+b))**2: print('Yes') else: print('No')
a,b,c = list(map(int,input().split())) if c-(a+b) < 0: print('No') elif 4*a*b < (c-(a+b))**2: print('Yes') else: print('No')
p02743
a, b, c = list(map(int, input().split())) ab = 4*a*b cab = c - a - b if cab <= 0: print("No") elif cab**2 - ab > 0: print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if c - a - b > 0: if 4*a*b < c*c + (a + b)*(a + b - 2*c): print("Yes") exit() print("No")
p02743
#!/usr/bin/env python3 from decimal import * a, b, c = list(map(int, input().split())) if a+b>c: print('No') exit() X = (a+b-c)**2 Y = a*b*4 if (Y<X): print('Yes') else: print('No')
#!/usr/bin/env python3 a, b, c = list(map(int, input().split())) if a+b>c: print('No') exit() f1 = 4*a*b - 2*a*b + 2*c*a + 2*b*c f2 = c**2 + b**2 + a**2 if f1 < f2: print('Yes') else: print('No')
p02743
import sys import copy from collections import deque stdin = sys.stdin mod = 10**9+7 ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n, k = na() a = na() def calc_lux(a): res = [0 for _ in range(len(a))] cnt = 0 for i in range(len(a)): light = a[i] if light==len(a) or (i <= light and n-1-i <= light): cnt += 1 continue for j in range(max(0, i-light), min(n-1, i+light)+1, 1): res[j] += 1 for i in range(len(res)): res[i] += cnt return res for _ in range(k): # calc lux from a lux = calc_lux(a) if a==lux: a = lux break # overwrite a a = lux # print(lux) print((" ".join([str(i) for i in a])))
import sys import copy from collections import deque stdin = sys.stdin mod = 10**9+7 ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n, k = na() a = na() def calc_lux(a): imosu = [0 for _ in range(len(a))] res = [0 for _ in range(len(a))] cnt = 0 for i in range(len(a)): light = a[i] le = max(0, i-light) imosu[le] += 1 if i+light < n-1: imosu[i+light+1] -= 1 tmp = 0 for i in range(len(res)): tmp += imosu[i] res[i] += tmp return res for _ in range(k): # calc lux from a lux = calc_lux(a) if a==lux: a = lux break # overwrite a a = lux # print(lux) print((" ".join([str(i) for i in a])))
p02647
N,K=list(map(int,input().split())) T=list(map(int,input().split())) if K==0: print(T) exit() if N<=K: L=[N]*N print(L) #S = [[0 for j in range(3)] for i in range(2)] 2行3列の場合 S = [[0 for j in range(N)] for i in range(K+1)] for i in range(N): S[0][i]=T[i] #print(S) for i in range(K): for j in range(N): d=S[i][j] #print(d) for k in range(max(j-d,0),min(j+d+1,N)): #print(k,max(j-d,0),min(j+d+1,K+1)) S[i+1][k]+=1 #print(S[K]) Z=[str(a) for a in S[K]] Z=" ".join(Z) print(Z)
N,K=list(map(int,input().split())) T=list(map(int,input().split())) if K==0: print(T) exit() if N<=K: L=[N]*N print(L) if K>100: K=100 #S = [[0 for j in range(3)] for i in range(2)] 2行3列の場合 S = [[0 for j in range(N)] for i in range(K+1)] for i in range(N): S[0][i]=T[i] #print(S) for i in range(K): for j in range(N): d=S[i][j] #print(d) for k in range(max(j-d,0),min(j+d+1,N)): #print(k,max(j-d,0),min(j+d+1,K+1)) S[i+1][k]+=1 #print(S[K]) Z=[str(a) for a in S[K]] Z=" ".join(Z) print(Z)
p02647
from itertools import accumulate N, K = list(map(int, input().split())) A = list(map(int, input().split())) for _ in range(K): if A == [N] * N: break B = [0] * (N+1) for i, a in enumerate(A): start = max(0, i - a) end = min(N-1, i + a) + 1 B[start] += 1 B[end] -= 1 A = list(accumulate(B))[:-1] print((' '.join(map(str, A))))
from itertools import accumulate N, K = list(map(int, input().split())) A = list(map(int, input().split())) for _ in range(K): if A == [N] * N: break B = [0] * (N+1) for i, a in enumerate(A): start = max(0, i - a) end = min(N-1, i + a) + 1 B[start] += 1 B[end] -= 1 A = list(accumulate(B))[:-1] print((' '.join(map(str, A))))
p02647
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections # import numpy as np mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N, K = LI() A = LI() """ 明るさが一定値を超えると計算しなくて良い 一定?d > math.floort(N/2) """ # lamps = [[0] * N] * (K + 1) lamps = [[0 for i in range(N)] for j in range(K + 1)] lamps[0] = A # lamps = np.array(lamps) if K > 40: b = [str(N)] * N print((" ".join(b))) sys.exit() for i in range(K): tmps = [0 for i in range(N)] for j in range(N): w = lamps[i][j] tmps[max(0, j - w)] += 1 r = min(N-1, j + w) if r + 1 < N: tmps[r + 1] -= 1 hoge = 0 for j in range(N): hoge += tmps[j] lamps[i + 1][j] = hoge ans = lamps[-1] ans = list(map(str, ans)) print((" ".join(ans)))
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N, K = LI() A = LI() """ 明るさが一定値を超えると計算しなくて良い 一定?d > math.floort(N/2) """ if K > 50: b = [str(N)] * N print((" ".join(b))) sys.exit() lamps = [[0 for i in range(N)] for j in range(K + 1)] lamps[0] = A """ 累積和〜 """ for i in range(K): if lamps[i] == [N for i in range(N)]: ans = [str(N) for i in range(N)] print((" ".join(ans))) tmps = [0 for i in range(N)] for j in range(N): w = lamps[i][j] tmps[max(0, j - w)] += 1 r = min(N-1, j + w) if r + 1 < N: tmps[r + 1] -= 1 hoge = 0 for j in range(N): hoge += tmps[j] lamps[i + 1][j] = hoge ans = lamps[-1] ans = list(map(str, ans)) print((" ".join(ans)))
p02647
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N, K = LI() A = LI() for i in range(K): A_new = [0 for i in range(N)] imos_table = [0 for i in range(N)] for j in range(N): left = max(0, j - A[j]) right = j + A[j] + 1 imos_table[left] += 1 if right >= N: pass else: imos_table[right] -= 1 tmp = 0 for j in range(N): tmp += imos_table[j] A_new[j] += tmp A = copy.deepcopy(A_new) print((" ".join(map(str, A))))
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N, K = LI() A = LI() if K > 50: print((" ".join([str(N) for i in range(N)]))) sys.exit() for i in range(K): A_new = [0 for i in range(N)] imos_table = [0 for i in range(N)] for j in range(N): left = max(0, j - A[j]) right = j + A[j] + 1 imos_table[left] += 1 if right >= N: pass else: imos_table[right] -= 1 tmp = 0 for j in range(N): tmp += imos_table[j] A_new[j] += tmp A = copy.deepcopy(A_new) print((" ".join(map(str, A))))
p02647
N, K = list(map(int, input().split())) A = [int(i) for i in input().split()] DP = [[0 for _ in range(N)] for _ in range(K+1)] for i in range(N): DP[0][i] = A[i] for i in range(1, K+1,1): for j in range(N): pl, mi = min(j + DP[i-1][j], N-1), max(j - DP[i-1][j], 0) for k in range(mi, pl+1, 1): DP[i][k] += 1 print((" ".join(map(str, DP[K]))))
import sys N, K = list(map(int, input().split())) if K > 42: print((" ".join(map(str, [N] * N)))) sys.exit() A = [int(i) for i in input().split()] DP = [[0 for _ in range(N)] for _ in range(K+1)] for i in range(N): DP[0][i] = A[i] for i in range(1, K+1,1): B = [0] * N for j in range(N): pl, mi = min(j + DP[i-1][j], N-1), max(j - DP[i-1][j], 0) B[mi] += 1 if pl + 1 < N: B[pl + 1] -= 1 for j in range(1, N): B[j] += B[j-1] DP[i] = B print((" ".join(map(str, DP[K]))))
p02647
import copy n,k=list(map(int,input().split())) a=list(map(int,input().split())) maxed={} for m in range(0,k): temp=[0]*n if len(maxed)==n: print((' '.join(map(str,a)))) for i in range(0,n): d=a[i] if d==n: temp[i]=n maxed[i]=1 elif d !=0 : for x in range(i-d, i+d+1): if x >= 0 and x < n : temp[x]+=1 else: temp[i]+=1 a=copy.copy(temp) print((' '.join(map(str,a))))
import copy n,k=list(map(int,input().split())) a=list(map(int,input().split())) maxed={} for m in range(0,k): temp=[0]*n if len(maxed)==n: print((' '.join(map(str,a)))) exit() for i in range(0,n): d=a[i] if d==n: temp[i]=n maxed[i]=1 elif d !=0 : for x in range(i-d, i+d+1): if x >= 0 and x < n : temp[x]+=1 else: temp[i]+=1 a=copy.copy(temp) print((' '.join(map(str,a))))
p02647
import sys from collections import deque import copy import math def main(): N, K = map(int, input().split()) a = [float(i) for i in input().split()] A = [0] * (N + 1) if K >= 41: for i in range(1, N+1): if i > 1: print(' ', end='') print(N, end='') print() sys.exit() for i in range(1, N+1): A[i] = a[i - 1] for _ in range(K): count = [0] * (N + 1) for i in range(1, N+1): if A[i] >= N: left_d = 1 right_d = N else: left_d = math.ceil(i - A[i] - 0.5) right_d = math.floor(i + A[i] + 0.5) if left_d < 1: left_d = 1 if right_d > N: right_d = N for j in range(left_d, right_d+1): count[j] += 1 A = copy.copy(count) for i in range(1, N+1): if i > 1: print(' ', end='') print(A[i], end='') print() if __name__ == '__main__': main()
import sys from collections import deque import copy import math def main(): N, K = map(int, input().split()) a = [int(i) for i in input().split()] A = [0] * (N + 1) if K >= 41: for i in range(1, N+1): if i > 1: print(' ', end='') print(N, end='') print() sys.exit() for i in range(1, N+1): A[i] = a[i - 1] for _ in range(K): count = [0] * (N + 1) for i in range(1, N+1): left_d = max(math.ceil(i - A[i]), 1) right_d = min(math.floor(i + A[i]), N) count[left_d] += 1 if right_d + 1 <= N: count[right_d + 1] -= 1 for i in range(1, N+1): count[i] += count[i - 1] A = copy.copy(count) for i in range(1, N+1): if i > 1: print(' ', end='') print(A[i], end='') print() if __name__ == '__main__': main()
p02647
N, K = list(map(int, input().split(" "))) A = list(map(int, input().split(" "))) for i in range(K): a = [0] * N for n, A_n in enumerate(A): b_min = 0 if n-A_n < 0 else n-A_n b_max = N-1 if n+A_n > N-1 else n+A_n b = [0] * (b_min) + [1] * (b_max+1 - b_min) + [0] * (N - b_max - 1) a = [ x + y for (x, y) in zip(a, b)] A = a print((" ".join(list(map(str, A)))))
import math N, K = list(map(int, input().split(" "))) A = list(map(int, input().split(" "))) for i in range(min(41, K)): B = [0] * N for n, A_n in enumerate(A): B_min = max(0, n-A_n) b_max = min(N-1, n+A_n) B[B_min] += 1 if b_max+1 < N: B[b_max+1] -= 1 sum = 0 for n in range(len(A)): sum += B[n] A[n] = sum print((" ".join(list(map(str, A)))))
p02647
#!/usr/bin/env python3 # vim: set fileencoding=utf-8 # pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation """Module docstring """ import functools import heapq import itertools import logging import math import os import random import string import sys from argparse import ArgumentParser from collections import defaultdict, deque from copy import deepcopy from io import BytesIO, IOBase from typing import Dict, List, Optional, Set, Tuple def solveFast(values: List[int], N: int, K: int) -> List[int]: result = [0] * N for v, i in sorted(((v, i) for i, v in enumerate(values)), reverse=True): v = max(v, K) for j in range(max(0, i - v), min(N, v + i + 1)): n = abs(j - i) if n == 0: result[j] += 1 else: result[j] += n * (n + 1) // 2 return result def solve(values: List[int], N: int, K: int) -> List[int]: if K >= N - 1: return [N] * N for _k in range(K): prev = values.copy() values = [0] * N for i, v in enumerate(prev): for j in range(max(0, i - v), min(N, v + i + 1)): values[j] += 1 if all(v == N for v in values): break return values def do_job(stdin, stdout): "Do the work" LOG.debug("Start working") # first line is number of test cases N, K = map(int, stdin.readline().split()) values = list(map(int, stdin.readline().split())) # values = [] # for _ in range(N): # values.append(stdin.readline().split()) result = solve(values, N, K) print(*result, file=stdout) def print_output(testcase: int, result, stdout) -> None: "Formats and print result" if result is None: result = "IMPOSSIBLE" print("Case #{}: {}".format(testcase + 1, result), file=stdout) # 6 digits float precision {:.6f} (6 is the default value) # print("Case #{}: {:f}".format(testcase + 1, result), file=stdout) BUFSIZE = 8192 class FastIO(IOBase): # pylint: disable=super-init-not-called, expression-not-assigned newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): # pylint: disable=super-init-not-called def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def configure_log() -> None: "Configure the log output" log_formatter = logging.Formatter("L%(lineno)d - " "%(message)s") handler = logging.StreamHandler(IOWrapper(sys.stderr)) handler.setFormatter(log_formatter) LOG.addHandler(handler) LOG = None # for interactive call: do not add multiple times the handler if not LOG: LOG = logging.getLogger("template") configure_log() def main(argv=None): "Program wrapper." if argv is None: argv = sys.argv[1:] parser = ArgumentParser() parser.add_argument( "-v", "--verbose", dest="verbose", action="store_true", default=False, help="run as verbose mode", ) args = parser.parse_args(argv) if args.verbose: LOG.setLevel(logging.DEBUG) stdin = IOWrapper(sys.stdin) stdout = IOWrapper(sys.stdout) do_job(stdin, stdout) stdout.flush() for h in LOG.handlers: h.flush() return 0 if __name__ == "__main__": sys.exit(main())
#!/usr/bin/env python3 # vim: set fileencoding=utf-8 # pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation """Module docstring """ import functools import heapq import itertools import logging import math import os import random import string import sys from argparse import ArgumentParser from collections import defaultdict, deque from copy import deepcopy from io import BytesIO, IOBase from typing import Dict, List, Optional, Set, Tuple def solveFast(values: List[int], N: int, K: int) -> List[int]: result = [0] * N for v, i in sorted(((v, i) for i, v in enumerate(values)), reverse=True): v = max(v, K) for j in range(max(0, i - v), min(N, v + i + 1)): n = abs(j - i) if n == 0: result[j] += 1 else: result[j] += n * (n + 1) // 2 return result def solve(values: List[int], N: int, K: int) -> List[int]: if K >= N - 1: return [N] * N for _k in range(K): prev = values.copy() values = [0] * N for i, v in enumerate(prev): l = max(0, i - v) r = min(N - 1, v + i) values[l] += 1 if r < N - 1: values[r + 1] -= 1 for i in range(1, N): values[i] += values[i - 1] if all(v == N for v in values): break return values def do_job(stdin, stdout): "Do the work" LOG.debug("Start working") # first line is number of test cases N, K = map(int, stdin.readline().split()) values = list(map(int, stdin.readline().split())) # values = [] # for _ in range(N): # values.append(stdin.readline().split()) result = solve(values, N, K) print(*result, file=stdout) def print_output(testcase: int, result, stdout) -> None: "Formats and print result" if result is None: result = "IMPOSSIBLE" print("Case #{}: {}".format(testcase + 1, result), file=stdout) # 6 digits float precision {:.6f} (6 is the default value) # print("Case #{}: {:f}".format(testcase + 1, result), file=stdout) BUFSIZE = 8192 class FastIO(IOBase): # pylint: disable=super-init-not-called, expression-not-assigned newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): # pylint: disable=super-init-not-called def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def configure_log() -> None: "Configure the log output" log_formatter = logging.Formatter("L%(lineno)d - " "%(message)s") handler = logging.StreamHandler(IOWrapper(sys.stderr)) handler.setFormatter(log_formatter) LOG.addHandler(handler) LOG = None # for interactive call: do not add multiple times the handler if not LOG: LOG = logging.getLogger("template") configure_log() def main(argv=None): "Program wrapper." if argv is None: argv = sys.argv[1:] parser = ArgumentParser() parser.add_argument( "-v", "--verbose", dest="verbose", action="store_true", default=False, help="run as verbose mode", ) args = parser.parse_args(argv) if args.verbose: LOG.setLevel(logging.DEBUG) stdin = IOWrapper(sys.stdin) stdout = IOWrapper(sys.stdout) do_job(stdin, stdout) stdout.flush() for h in LOG.handlers: h.flush() return 0 if __name__ == "__main__": sys.exit(main())
p02647
# 問題文の意味がわからんコンテスト # 0の場合も自分自身を照らす、っての気づくところからやっと読解 # Kを5000兆回やったあとはすべての要素がNになっとる この収束はわりと早いらしい n, k = list(map(int, input().split())) a = list(map(int, input().split())) for _ in range(k): b = [0] * (n + 1) for i in range(n): b[max(0, i - a[i])] += 1 b[min(n, i + a[i] + 1)] -= 1 for i in range(n): b[i + 1] += b[i] a = b[:n] if b[-1] == n: break print((" ".join(list(map(str, a)))))
# 問題文の意味がわからんコンテスト # 0の場合も自分自身を照らす、っての気づくところからやっと読解 # Kを5000兆回やったあとはすべての要素がNになっとる この収束はわりと早いらしい n, k = list(map(int, input().split())) a = list(map(int, input().split())) for _ in range(min(k, 100)): b = [0] * (n + 1) for i in range(n): b[max(0, i - a[i])] += 1 b[min(n, i + a[i] + 1)] -= 1 for i in range(n): b[i + 1] += b[i] a = b[:n] print((" ".join(list(map(str, a)))))
p02647
N, K = list(map(int, input().split())) A = list(map(int, input().split())) import sys import math if K > 3.5962*math.log(N): A = [N]*N print((' '.join(map(str, A)))) sys.exit() lenA = len(A) for i in range(K): B = [0 for _ in range(lenA)] # print(B) for j in range(lenA): num = A[j] # print(j, num) B[max(0, j - num): min(lenA, j + num + 1)] = [b + 1 for b in B[max(0, j - num): min(lenA, j + num + 1)]] # print(j, B) if all([a == b for a, b in zip(A,B)]): # print('same') break else: A = B #print(i+1) print((' '.join(map(str, A))))
N, K = list(map(int, input().split())) A = list(map(int, input().split())) lenA = len(A) for i in range(K): B = [0 for _ in range(lenA)] # print(B) for j in range(lenA): num = A[j] # print(j, num) if j - num >= 0: B[max(0, j - num)] += 1 else: B[0] += 1 if j + num + 1 < lenA: B[min(lenA, j + num + 1)] -= 1 # print(j, B) for i in range(1, lenA): B[i] = B[i-1] + B[i] if all([a == b for a, b in zip(A,B)]): # print('same') break else: A = B #print(i+1) print((' '.join(map(str, A))))
p02647
n, k = list(map(int, input().split())) a = list(map(int , input().split())) for i in range(k): tmp = [0] * n for j in range(n): for k in range(a[j]*2+1): if (j - a[j] + k) >= 0 and (j - a[j] + k) < n: tmp[(j - a[j] + k)] += 1 if min(a) == n: print((' '.join(map(str, a)))) exit() a = tmp print((' '.join(map(str, a)))) # 10 5 # 20 8 # 40 10 # 80 12 # 160 15
n, k = list(map(int, input().split())) a = list(map(int , input().split())) for i in range(k): s = [0] * (n + 1) for j in range(n): l = max(0, j - a[j]) r = min(n, j + a[j]+1) s[l] += 1 s[r] += -1 m = s[0] for j in range(1,n+1): s[j] += s[j-1] if j < n: m = min(m, s[j]) a = s[:-1] if m == n: print((' '.join(map(str, a)))) exit() print((' '.join(map(str, a))))
p02647
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(eval(input())) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=' '): print((k.join(list(map(str, lst))))) INF = float('inf') # from math import ceil, floor, log2 # from collections import deque from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush # import numpy as np # from numpy import cumsum # accumulate def solve(): N, K = MI() A = LI() for i in range(K): B = [0] * N for idx, a in enumerate(A): l = max(0, idx - a) r = idx + a + 1 # print(idx, a, l, r) B[l] += 1 if N > r: B[r] -= 1 # print(B) B = list(accumulate(B)) # print(B) if A == B: printlist(A) return A = B printlist(A) if __name__ == '__main__': solve()
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(eval(input())) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=' '): print((k.join(list(map(str, lst))))) INF = float('inf') # from math import ceil, floor, log2 # from collections import deque from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush # import numpy as np # from numpy import cumsum # accumulate def solve(): N, K = MI() A = LI() for i in range(K): B = [0] * N for idx, a in enumerate(A): l = max(0, idx - a) r = idx + a + 1 # print(idx, a, l, r) B[l] += 1 if N > r: B[r] -= 1 # print(B) B = list(accumulate(B)) # print(B) if all([j == N for j in B]): printlist(B) return A = B printlist(A) if __name__ == '__main__': solve()
p02647
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return map(fn, readline().split()) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): n, k = geta(int) a = tuple(geta(int)) def update(b): r = [0] * n for i, bi in enumerate(b): i1 = max(0, i - bi) i2 = min(n - 1, i + bi) r[i1] += 1 if i2 < n - 1: r[i2 + 1] -= 1 for i in range(1, n): r[i] += r[i - 1] return r for i in range(k): a = update(a) print(*a, sep=" ") if __name__ == "__main__": main()
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return map(fn, readline().split()) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): n, k = geta(int) a = tuple(geta(int)) def update(b): r = [0] * n for i, bi in enumerate(b): i1 = max(0, i - bi) i2 = min(n - 1, i + bi) r[i1] += 1 if i2 < n - 1: r[i2 + 1] -= 1 updated = (not r[0] == b[0]) for i in range(1, n): r[i] += r[i - 1] if r[i] != b[i]: updated = True return r, updated for i in range(k): a, updated = update(a) if not updated: break print(*a, sep=" ") if __name__ == "__main__": main()
p02647
n,k=list(map(int,input().split())) a=list(map(int,input().split())) import heapq # heapqライブラリのimport #heapq.heapify(a) # リストを優先度付きキューへ #heapq.heappop(a) # 最小値の取り出し #heapq.heappush(a, -2) import copy for unko in range(min(k,50)): denkyu=[] heapq.heapify(denkyu) cnt=0 ans=[0]*n #print("start",a) for i,aa in enumerate(a): if cnt==0: ans[i]+=1 if aa>0: cnt+=1 heapq.heappush(denkyu,i+aa+1) else: while 1: tmp=heapq.heappop(denkyu) if i<tmp: heapq.heappush(denkyu, tmp) break else: cnt-=1 if cnt==0: break ans[i]+=cnt+1 if aa>0: cnt+=1 heapq.heappush(denkyu,i+aa+1) #print(aa,denkyu) #print(unko,ans,a) denkyu=[] heapq.heapify(denkyu) cnt=0 for ii in range(n): i=n-ii-1 if cnt==0: if a[i]>0: cnt+=1 heapq.heappush(denkyu,-1*(i-a[i]-1)) else: while 1: tmp=heapq.heappop(denkyu)*(-1) if i>tmp: heapq.heappush(denkyu, tmp*(-1)) break else: cnt-=1 if cnt==0: break ans[i]+=cnt if a[i]>0: cnt+=1 heapq.heappush(denkyu,(i-a[i]-1)*(-1)) #print("migi",a[i],denkyu) a = copy.deepcopy(ans) #print(unko,a) print((" ".join(list(map(str,a)))))
n,k=list(map(int,input().split())) a=list(map(int,input().split())) for _ in range(k): imos=[0]*(n+1) for i in range(n): imos[max(0,i-a[i])]+=1 imos[min(n,1+i+a[i])]-=1 a[0]=imos[0] if a[0]==n: flag=0 else: flag=1 for i in range(1,n): a[i]=a[i-1]+imos[i] if a[i]!=n: flag=1 if flag==0: break print((" ".join(list(map(str,a)))))
p02647
import math N,K = list(map(int,input().split())) A = list(map(int,input().split())) for j in range(min(K,int(2*(math.log2(N)))+1)): B = [0]*N for i in range(N): l = max(0,i-A[i]) r = min(N-1,i+A[i]) B[l] += 1 if r < N-1: B[r+1] -= 1 for i in range(1,N): B[i] += B[i-1] A = B print((' '.join(map(str,A))))
import math N,K = list(map(int,input().split())) A = list(map(int,input().split())) for j in range(min(K,int(2*(math.log2(N)))+10)): B = [0]*N for i in range(N): l = max(0,i-A[i]) r = min(N-1,i+A[i]) B[l] += 1 if r < N-1: B[r+1] -= 1 for i in range(1,N): B[i] += B[i-1] A = B print((' '.join(map(str,A))))
p02647
import sys sys.setrecursionlimit(10 ** 7) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, K = list(map(int, input().split())) A = list(map(int, input().split())) K = min(K, 50) for _ in range(K): imos = [0] * (N + 1) for i in range(N): a = A[i] s = max(0, i - a) e = min(N, i + a + 1) imos[s] += 1 imos[e] -= 1 nxt = [0] * N t = 0 for i in range(N): t += imos[i] nxt[i] = t A = nxt print((" ".join(map(str, A))))
import sys sys.setrecursionlimit(10 ** 7) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, K = list(map(int, input().split())) A = list(map(int, input().split())) K = min(K, 100) for _ in range(K): imos = [0] * (N + 1) for i in range(N): a = A[i] s = max(0, i - a) e = min(N, i + a + 1) imos[s] += 1 imos[e] -= 1 nxt = [0] * N t = 0 for i in range(N): t += imos[i] nxt[i] = t A = nxt print((" ".join(map(str, A))))
p02647
import sys,bisect,string,math,time,functools,random,fractions from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby rep=range def Golf():n,*t=map(int,open(0).read().split()) def I():return int(input()) def S_():return input() def IS():return input().split() def LS():return [i for i in input().split()] def MI():return map(int,input().split()) def LI():return [int(i) for i in input().split()] def LI_():return [int(i)-1 for i in input().split()] def NI(n):return [int(input()) for i in range(n)] def NI_(n):return [int(input())-1 for i in range(n)] def StoLI():return [ord(i)-97 for i in input()] def ItoS(n):return chr(n+97) def LtoS(ls):return ''.join([chr(i+97) for i in ls]) def RA():return map(int,open(0).read().split()) def GI(V,E,ls=None,Directed=False,index=1): org_inp=[];g=[[] for i in range(V)] FromStdin=True if ls==None else False for i in range(E): if FromStdin: inp=LI() org_inp.append(inp) else: inp=ls[i] if len(inp)==2: a,b=inp;c=1 else: a,b,c=inp if index==1:a-=1;b-=1 aa=(a,c);bb=(b,c);g[a].append(bb) if not Directed:g[b].append(aa) return g,org_inp def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1): #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage mp=[boundary]*(w+2);found={} for i in range(h): s=input() for char in search: if char in s: found[char]=((i+1)*(w+2)+s.index(char)+1) mp_def[char]=mp_def[replacement_of_found] mp+=[boundary]+[mp_def[j] for j in s]+[boundary] mp+=[boundary]*(w+2) return h+2,w+2,mp,found def TI(n):return GI(n,n-1) def accum(ls): rt=[0] for i in ls:rt+=[rt[-1]+i] return rt def bit_combination(n,base=2): rt=[] for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s] return rt def gcd(x,y): if y==0:return x if x%y==0:return y while x%y!=0:x,y=y,x%y return y def show(*inp,end='\n'): if show_flg:print(*inp,end=end) YN=['YES','NO'];Yn=['Yes','No'] mo=10**9+7 inf=float('inf') FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb)) l_alp=string.ascii_lowercase #sys.setrecursionlimit(10**7) read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline input=lambda: sys.stdin.readline().rstrip() class Tree: def __init__(self,inp_size=None,ls=None,init=True,index=1): self.LCA_init_stat=False self.ETtable=[] if init: if ls==None: self.stdin(inp_size,index=index) else: self.size=len(ls)+1 self.edges,_=GI(self.size,self.size-1,ls,index=index) return def stdin(self,inp_size=None,index=1): if inp_size==None: self.size=int(input()) else: self.size=inp_size self.edges,_=GI(self.size,self.size-1,index=index) return def listin(self,ls,index=0): self.size=len(ls)+1 self.edges,_=GI(self.size,self.size-1,ls,index=index) return def dfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0): q=deque([x]) v=[None]*self.size v[x]=root_v while q: c=q.pop() for nb,d in self.edges[c]: if v[nb]==None: q.append(nb) v[nb]=func(c,v[c],nb,d) return v def bfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0): q=deque([x]) v=[None]*self.size v[x]=root_v while q: c=q.popleft() for nb,d in self.edges[c]: if v[nb]==None: q.append(nb) v[nb]=func(c,v[c],nb,d) return v def parent(self,x): return self.dfs(0,func=lambda pr,prv,nx,dist:pr,root_v=-1) def topological_sort(self,x): # return topological sort of the tree tps=[] q=deque([x]) v=[None]*self.size v[x]=0 while q: c=q.popleft() tps.append(c) for nb,d in self.edges[c]: if v[nb]==None: q.append(nb) v[nb]=0 return tps def EulerTour(self,x): q=deque() q.append(x) self.depth=[None]*self.size self.depth[x]=0 self.ETtable=[] self.ETdepth=[] self.ETin=[-1]*self.size self.ETout=[-1]*self.size cnt=0 while q: c=q.pop() if c<0: ce=~c else: ce=c for nb,d in self.edges[ce]: if self.depth[nb]==None: q.append(~ce) q.append(nb) self.depth[nb]=self.depth[ce]+1 self.ETtable.append(ce) self.ETdepth.append(self.depth[ce]) if self.ETin[ce]==-1: self.ETin[ce]=cnt else: self.ETout[ce]=cnt cnt+=1 return def LCA_init(self,root): self.EulerTour(root) self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf) #self.st=SegTree(self.size*2-1,self.ETdepth,function=min,ide=inf) self.LCA_init_stat=True return def LCA(self,root,x,y): if self.LCA_init_stat==False: self.LCA_init(root) xin,xout=self.ETin[x],self.ETout[x] yin,yout=self.ETin[y],self.ETout[y] a=min(xin,yin) b=max(xout,yout,xin,yin) id_of_min_dep_in_et=self.st.query_id(a,b+1) return self.ETtable[id_of_min_dep_in_et] def __str__(self): return str(self.edges) def show(self): if all([all([d==1 for nd,d in edge]) for edge in self.edges]): print( [[nd for nd,d in edge] for edge in self.edges] ) else: print(self) class SparseTable: # O(N log N) for init, O(1) for query(l,r) def __init__(self,ls,init_func=min,init_idl=float('inf')): self.func=init_func self.idl=init_idl self.size=len(ls) self.N0=self.size.bit_length() self.table=[ls[:]] self.index=[list(range(self.size))] self.lg=[0]*(self.size+1) for i in range(2,self.size+1): self.lg[i]=self.lg[i>>1]+1 for i in range(self.N0): tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)] tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)] self.table+=[tmp] self.index+=[tmp_id] # return func of [l,r) def query(self,l,r): if r>self.size:r=self.size #N=(r-l).bit_length()-1 N=self.lg[r-l] return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]) # return index of which val[i] = func of v among [l,r) def query_id(self,l,r): if r>self.size:r=self.size #N=(r-l).bit_length()-1 N=self.lg[r-l] a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))] if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]): b=a return b # return boundary index of r such that func({table[i]} =< x , i in [pos,r] def right_bound(self,pos,x): k=(self.size-pos).bit_length() for j in range(k)[::-1]: nx=pos+(1<<j) if nx<n and self.query(pos,nx+1)<=x: pos+=(1<<j) return pos # return boundary index of l such that func({table[i]} =< x , i in [l,pos] def left_bound(self,pos,x): k=pos.bit_length() for j in range(k)[::-1]: nx=pos-(1<<j) if 0<=nx and self.query(nx,pos+1)<=x: pos-=(1<<j) return pos def __str__(self): return str(self.table[0]) def print(self): for i in self.table: print(*i) show_flg=False show_flg=True ans=0 n,k=LI() a=[0]+LI()+[0] T=min(k,100) for t in range(T): nx=[0]*(n+2) for i in range(1,n+1): l=max(0,i-a[i]) r=min(i+a[i]+1,n+1) nx[l]+=1 nx[r]+=-1 #print(a,nx) for i in range(n+1): nx[i+1]+=nx[i] a=nx print(*a[1:n+1])
import sys,bisect,string,math,time,functools,random,fractions from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby rep=range;R=range def Golf():n,*t=map(int,open(0).read().split()) def I():return int(input()) def S_():return input() def IS():return input().split() def LS():return [i for i in input().split()] def MI():return map(int,input().split()) def LI():return [int(i) for i in input().split()] def LI_():return [int(i)-1 for i in input().split()] def NI(n):return [int(input()) for i in range(n)] def NI_(n):return [int(input())-1 for i in range(n)] def NLI(n):return [[int(i) for i in input().split()] for i in range(n)] def NLI_(n):return [[int(i)-1 for i in input().split()] for i in range(n)] def StoLI():return [ord(i)-97 for i in input()] def ItoS(n):return chr(n+97) def LtoS(ls):return ''.join([chr(i+97) for i in ls]) def RA():return map(int,open(0).read().split()) def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)] def RI(a=1,b=10):return random.randint(a,b) def Rtest(T): case,err=0,0 for i in range(T): inp=INP() a1,ls=naive(*inp) a2=solve(*inp) if a1!=a2: print((a1,a2),inp) err+=1 case+=1 print('Tested',case,'case with',err,'errors') def GI(V,E,ls=None,Directed=False,index=1): org_inp=[];g=[[] for i in range(V)] FromStdin=True if ls==None else False for i in range(E): if FromStdin: inp=LI() org_inp.append(inp) else: inp=ls[i] if len(inp)==2: a,b=inp;c=1 else: a,b,c=inp if index==1:a-=1;b-=1 aa=(a,c);bb=(b,c);g[a].append(bb) if not Directed:g[b].append(aa) return g,org_inp def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1): #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage mp=[boundary]*(w+2);found={} for i in R(h): s=input() for char in search: if char in s: found[char]=((i+1)*(w+2)+s.index(char)+1) mp_def[char]=mp_def[replacement_of_found] mp+=[boundary]+[mp_def[j] for j in s]+[boundary] mp+=[boundary]*(w+2) return h+2,w+2,mp,found def TI(n):return GI(n,n-1) def accum(ls): rt=[0] for i in ls:rt+=[rt[-1]+i] return rt def bit_combination(n,base=2): rt=[] for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s] return rt def gcd(x,y): if y==0:return x if x%y==0:return y while x%y!=0:x,y=y,x%y return y def YN(x):print(['NO','YES'][x]) def Yn(x):print(['No','Yes'][x]) def show(*inp,end='\n'): if show_flg:print(*inp,end=end) mo=10**9+7 #mo=998244353 inf=float('inf') FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb)) l_alp=string.ascii_lowercase #sys.setrecursionlimit(10**9) read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip() show_flg=False show_flg=True ans=0 n,k=LI() a=LI() def f(b): rt=[0]*-~n for i in range(n): d=b[i] rt[max(0,i-d)]+=1 rt[min(n,i+d+1)]+=-1 for i in range(n-1): rt[i+1]+=rt[i] return rt[:-1] for i in range(k): a=f(a) if sum(a)==n**2: break print(*a)
p02647
#import numpy as np import sys, math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial#, gcd from bisect import bisect_left #bisect_left(list, value) sys.setrecursionlimit(10**7) enu = enumerate MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] pl = lambda x: print(*x, sep='\n') N, K = map(int, input().split()) A = list(map(int, input().split())) def func(A): aA = [0]*(2*N+10) for i, a in enu(A): st = max(0, 2*i-2*a-1) en = min(2*N, 2*i+2*a+1) aA[st] += 1 aA[en] -= 1 for i in range(2*N): aA[i+1] += aA[i] res = [val for i, val in enu(aA) if i%2==0] res = res[:N] return res for _ in range(K): A = func(A) print(*A)
#import numpy as np import sys, math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial#, gcd from bisect import bisect_left #bisect_left(list, value) sys.setrecursionlimit(10**7) enu = enumerate MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] pl = lambda x: print(*x, sep='\n') N, K = map(int, input().split()) A = list(map(int, input().split())) # print('A', A) def func(A): # print('start') # print(A) all_N = True aA = [0]*(2*N+10) for i, a in enu(A): if a != N: all_N = False st = max(0, 2*i-2*a-1) en = min(2*N, 2*i+2*a+1) aA[st] += 1 aA[en] -= 1 # print(aA) for i in range(2*N): aA[i+1] += aA[i] # print(aA) res = [val for i, val in enu(aA) if i%2==0] res = res[:N] # print(res) return res, all_N for _ in range(K): A, all_N = func(A) if all_N: break # print(*A) print(*A)
p02647
n, k = list(map(int, input().split())) a = list(map(int, input().split())) for j in range(k): b = [0]*n for i in range(n): l = max(0, i-a[i]) r = min(n, i+a[i]+1) b[l] += 1 if r < n: b[r] -= 1 for i in range(1, n): b[i]+=b[i-1] a = b if a.count(n) == n: break print((" ".join(list(map(str, a)))))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) for j in range(min(k, 41)): b = [0]*n for i in range(n): l = max(0, i-a[i]) r = min(n, i+a[i]+1) b[l] += 1 if r < n: b[r] -= 1 for i in range(1, n): b[i]+=b[i-1] a = b print((" ".join(list(map(str, a)))))
p02647
def examA(): S = SI() ans = S[:3] print(ans) return def examB(): A, V = LI() B, W = LI() T = I() L = abs(A-B) v = V-W if v*T>=L: ans = "YES" else: ans = "NO" print(ans) return def examC(): # 区間加算、上書き、一点取得 class SegmentTree: def __init__(self, n, ele, segfun): #####単位元######要設定0or1orinf self.ide_ele = ele self.segfun = segfun #################### self.n = n self.N0 = 1 << n.bit_length() self.data = [self.ide_ele] * (self.N0 * 2) def ref(self): self.data = [self.ide_ele] * (self.N0 * 2) return def update_add(self, l, r, val): l += self.N0 r += self.N0 while l < r: if l & 1: self.data[l] += val l += 1 if r & 1: self.data[r - 1] += val r -= 1 l //= 2 r //= 2 def update(self, l, r, val): l += self.N0 r += self.N0 while l < r: if l & 1: self.data[l] = self.segfun(self.data[l], val) l += 1 if r & 1: self.data[r - 1] = self.segfun(self.data[r - 1], val) r -= 1 l //= 2 r //= 2 def query(self, i): i += len(self.data) // 2 ret = self.data[i] while i > 0: i //= 2 ret = self.segfun(ret, self.data[i]) return ret N, K = LI() A = LI() S = SegmentTree(N+1,0,lambda a, b: a+b) for i in range(N): S.update(i,i+1,A[i]) #for i in range(N): # print(S.query(i)) for _ in range(min(60,K)): cur = N L = [] R = [] for i in range(N): a = S.query(i) L.append(max(0,i-a)) R.append(min(N,i+a+1)) if cur>a: cur = a if cur==N: break S.ref() for l,r in zip(L,R): S.update_add(l,r,1) #for i in range(N): # print(S.query(i)) #input() ans = [S.query(i) for i in range(N)] print((" ".join(map(str,ans)))) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return def test(): i = I() li = LI() lsi = LSI() si = LS() print(i) print(li) print(lsi) print(si) return from decimal import Decimal as dec import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(eval(input())) def LI(): return list(map(int,sys.stdin.readline().split())) def DI(): return dec(eval(input())) def LDI(): return list(map(dec,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == '__main__': examC() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
def examA(): S = SI() ans = S[:3] print(ans) return def examB(): A, V = LI() B, W = LI() T = I() L = abs(A-B) v = V-W if v*T>=L: ans = "YES" else: ans = "NO" print(ans) return def examC(): N, K = LI() A = LI() for _ in range(min(60,K)): cur = N L = [0] * (N + 1) R = [0] * (N + 1) for i in range(N): a = A[i] if 0<i-a: L[i-a] += 1 else: L[0] += 1 if N>i+a+1: R[i+a+1] += 1 else: R[N] += 1 if cur>a: cur = a if cur==N: break A[0] = L[0] for i in range(1,N): A[i] = A[i-1]+L[i]-R[i] print((" ".join(map(str,A)))) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return def test(): i = I() li = LI() lsi = LSI() si = LS() print(i) print(li) print(lsi) print(si) return from decimal import Decimal as dec import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(eval(input())) def LI(): return list(map(int,sys.stdin.readline().split())) def DI(): return dec(eval(input())) def LDI(): return list(map(dec,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == '__main__': examC() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
p02647
#coding; utf-8 import copy N, k = list(map(int,input().split())) A = list(map(int,input().split())) B = [0] * N A = [0] + A #B = copy.copy(A) for j in range(k): #print(A) n_light = [0] * (N+1) for i in range(N): d = A[i+1] l = i+1-d r = i+1+d #print(l, r) n_light[max(l, 1)] += 1 if r+1 <= N:# and l != r: n_light[r+1] -= 1 #print(n_light) #print(n_light) for i in range(1,N): n_light[i+1] += n_light[i] n_str = [str(i) for i in n_light] A = n_light print((' '.join(n_str[1:])))
#coding; utf-8 import copy N, k = list(map(int,input().split())) A = list(map(int,input().split())) B = [0] * N A = [0] + A #B = copy.copy(A) #k = 10 for j in range(k): #print(A) n_light = [0] * (N+1) for i in range(N): d = A[i+1] l = i+1-d r = i+1+d #print(l, r) n_light[max(l, 1)] += 1 if r+1 <= N:# and l != r: n_light[r+1] -= 1 #print(n_light) #print(n_light) for i in range(1,N): n_light[i+1] += n_light[i] n_str = [str(i) for i in n_light] if len(set(n_light[1:])) == 1 and j > 2: #print(n_light) break #n_str = [str(i) for i in n_light] A = n_light #print(n_light) print((' '.join(n_str[1:])))
p02647
n, k = list(map(int, input().split())) a = list(map(int, input().split())) for i in range(k): acc = [0 for j in range(n+1)] for j in range(n): acc[max(0, j - a[j])] += 1 acc[min(n-1, j + a[j]) + 1] -= 1 for j in range(n): acc[j+1] += acc[j] a = acc[:-1] if sum(a) == n * (n-1): break print((" ".join(map(str, a))))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) for i in range(k): acc = [0 for j in range(n+1)] for j in range(n): acc[max(0, j - a[j])] += 1 acc[min(n-1, j + a[j]) + 1] -= 1 for j in range(n): acc[j+1] += acc[j] a = acc[:-1] if sum(a) == n * n: break print((" ".join(map(str, a))))
p02647
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] _LI = lambda : [-int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) SI = lambda : sys.stdin.readline().rstrip() DD = ((1,0),(0,1),(-1,0),(0,-1)) N,K = LI() a = LI() for _ in range(K): x = [0] * N for i in range(N): s = i - a[i] if s < 0: s = 0 x[s] += 1 t = i + a[i] + 1 if t < N: x[t] -= 1 a = [] cnt = 0 for i in range(N): cnt += x[i] a.append(cnt) print(*a,sep=' ') if __name__ == '__main__': main()
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] _LI = lambda : [-int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) SI = lambda : sys.stdin.readline().rstrip() DD = ((1,0),(0,1),(-1,0),(0,-1)) N,K = LI() a = LI() for _ in range(K): x = [0] * N for i in range(N): s = i - a[i] if s < 0: s = 0 x[s] += 1 t = i + a[i] + 1 if t < N: x[t] -= 1 a = [] cnt = 0 finish = True for i in range(N): cnt += x[i] if cnt < N: finish = False a.append(cnt) if finish: break print(*a,sep=' ') if __name__ == '__main__': main()
p02647
n,k=list(map(int,input().split())) a=list(map(int,input().split())) for _ in range(k): add_a=[0]*(n+1) for i in range(n): a[i] add_a[max(0,i-a[i])]+=1 add_a[min(n,i+a[i]+1)]-=1 tmp=0 for i in range(n): tmp+=add_a[i] a[i]=tmp print((' '.join(map(str,a))))
n,k=list(map(int,input().split())) a=list(map(int,input().split())) for _ in range(min(k,int(n**0.5)+10)): add_a=[0]*(n+1) for i in range(n): a[i] add_a[max(0,i-a[i])]+=1 add_a[min(n,i+a[i]+1)]-=1 tmp=0 for i in range(n): tmp+=add_a[i] a[i]=tmp print((' '.join(map(str,a))))
p02647
def main(): n,k,*a=list(map(int,open(0).read().split())) for _ in range(k): b=[0]*n m=10**18 for i,t in enumerate(a): if t<m:m=t b[max(0,i-t)]+=1 if i-~t<n:b[i-~t]-=1 if m>n:break for i in range(n-1):b[i+1]+=b[i] a=b print((' '.join(map(str,a)))) main()
def main(): n,k,*a=list(map(int,open(0).read().split())) for _ in range(k): b=[0]*n m=10**18 for i,t in enumerate(a): if t<m:m=t b[max(0,i-t)]+=1 if i-~t<n:b[i-~t]-=1 if m>=n:break for i in range(n-1):b[i+1]+=b[i] a=b print((' '.join(map(str,a)))) main()
p02647
def main(): from itertools import accumulate n,k,*a=list(map(int,open(0).read().split())) for _ in range(k): b=[0]*n for i,t in enumerate(a): b[i-t if i>t else 0]+=1 if i-~t<n:b[i-~t]-=1 *a,=accumulate(b) if min(a)==n:break print((' '.join(map(str,a)))) main()
def main(): from itertools import accumulate n,k,*a=list(map(int,open(0).read().split())) for _ in range(k): b=[0]*n for i,t in enumerate(a): if(j:=i-t)<0:j=0 b[j]+=1 if(j:=i-~t)<n:b[j]-=1 *a,=accumulate(b) if min(a)==n:break print((' '.join(map(str,a)))) main()
p02647
import math N,K=list(map(int,input().split())) A=[0]*N A=list(map(int,input().split())) da=[0 for i in range(N)] for k in range(K): B=[0 for i in range(N)] for i in range(N): l=max(0,i-A[i]) r=min(N-1,i+A[i]) B[l]=B[l]+1 if(r+1<N): B[r+1]=B[r+1]-1 for i in range(1,N): B[i]=min(N,B[i]+B[i-1]) A=B b=[str(i) for i in B] b=" ".join(b) print(b)
import math N,K=list(map(int,input().split())) A=[0]*N A=list(map(int,input().split())) da=[0 for i in range(N)] for k in range(K): B=[0 for i in range(N)] for i in range(N): l=max(0,i-A[i]) r=min(N-1,i+A[i]) B[l]=B[l]+1 if(r+1<N): B[r+1]=B[r+1]-1 for i in range(1,N): B[i]=min(N,B[i]+B[i-1]) if(A==B): break A=B b=[str(i) for i in B] b=" ".join(b) print(b)
p02647
def resolve(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) bn1 = [0] * n bn2 = [0] * n s = 0 t = 0 chec=0 for _ in range(k): for i in range(n): b1 = max(i - a[i], 0) b2 = min(i + a[i], n - 1) bn1[b1] += 1 bn2[b2] += 1 for i in range(n): s += bn1[i] a[i] = s s = 0 for i in range(1, n): t += bn2[i - 1] a[i] -= t if a[i]==n: chec+=1 if chec==n: break chec=0 t = 0 bn1 = [0] * n bn2 = [0] * n c = [str(x) for x in a] L = " ".join(c) print(L) resolve()
def resolve(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) bn1 = [0] * n s = 0 t = 0 chec = 0 for _ in range(k): for i in range(n): b1 = max(i - a[i], 0) b2 = min(i + a[i], n - 1) bn1[b1] += 1 if b2<n-1: bn1[b2+1] -= 1 for i in range(n): s += bn1[i] a[i] = s if s==n: chec+=1 s = 0 if chec == n: break chec = 0 bn1 = [0] * n c = [str(x) for x in a] L = " ".join(c) print(L) resolve()
p02647
# coding: utf-8 #import numpy as np import re import math from collections import defaultdict from collections import deque import collections from fractions import Fraction import bisect from queue import PriorityQueue import itertools from itertools import accumulate from copy import deepcopy import random import time import os import sys import datetime from functools import lru_cache from functools import reduce readline=sys.stdin.readline sys.setrecursionlimit(2000000) alphabet="abcdefghijklmnopqrstuvwxyz" numbers="0123456789" mod=int(10**9+7) inf=int(10**19) class Edge(): def __init__(self,x,y,val=1): self.x=x self.y=y self.val=val class unionfind(): def __init__(self,n): self.n=n self.P=[a for a in range(n)] self.rank=[0]*n def find(self,x): if(x!=self.P[x]): self.P[x]=self.find(self.P[x]) return self.P[x] def same(self,x,y): return self.find(x)==self.find(y) def link(self,x,y): if self.rank[x]<self.rank[y]: self.P[x]=y elif self.rank[y]<self.rank[x]: self.P[y]=x else: self.P[x]=y self.rank[y]+=1 def unite(self,x,y): self.link(self.find(x),self.find(y)) def size(self): S=set() for a in range(self.n): S.add(self.find(a)) return len(S) def yn(b): if b:print("yes") else:print("no") def Yn(b): if b:print("Yes") else:print("No") def YN(b): if b:print("YES") else:print("NO") def ispow(a,b): now=b while now<a: now*=b return now==a def getbin(num,size): A=[0]*size for a in range(size): if (num>>(size-a-1))&1==1: A[a]=1 else: A[a]=0 return A def getfacs(n,mod_=0): A=[1]*(n+1) for a in range(2,len(A)): A[a]=A[a-1]*a if(mod_>0):A[a]%=mod_ return A def comb(n,r,mod,fac): if(n-r<0):return 0 return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod def nextcomb(num,size): x=num&(-num) y=num+x z=num&(~y) z//=x z=z>>1 num=(y|z) if(num>=(1<<size)):return False else:return num def getprimes(n): if n==0:return [] A=[True]*(n+1) A[0]=False A[1]=False for a in range(2,n+1): if A[a]: for b in range(a*2,n+1,a): A[b]=False ret=[] for a in range(n+1): if(A[a]):ret.append(a) return ret def isprime(num): if(num<=1):return False i=2 while i*i<=num: if(num%i==0):return False i+=1 return True def ifelse(bbool,ret1,ret2): if bbool:return ret1 else:return ret2 def join(A,c=" "): n=len(A) A=list(map(str,A)) s="" for a in range(n): s+=A[a] if(a<n-1):s+=c return s def factorize(n): b = 2 ret=defaultdict(int) while b * b <= n: while n % b == 0: n //= b ret[b]+=1 b+=1 if n > 1:ret[n]+=1 return ret def pm(x): return x//abs(x) def inputintlist(): return list(map(int,input().split())) def inputfloatlist(): return list(map(float,input().split())) def tozero(A): ret=[None]*len(A) for a in range(len(A)): ret[a]=A[a]-1 return ret def istanchouzouka(A): f=True prev=min(A)-1 for a in A: if prev>=a: f=False prev=a return f def istanchouhigensyou(A): f=True prev=min(A)-1 for a in A: if prev>a: f=False prev=a return f def getallsum(A): s=sum(A) dp=defaultdict(int) dp[0]=1 for a in range(0,len(A)): for b in range(s,-1,-1): if b-A[a]>=0: dp[b]+=dp[b-A[a]] return dp def yuukoutomukou(edges): ret=deepcopy(edges) for edge in edges: if not edge.x==edge.y: ret.append(Edge(edge.y,edge.x,edge.val)) return ret def dijkstra(edges,V,start): mincost=[inf]*V G=[[] for a in range(V)] for edge in edges: G[edge.x].append([edge.val,edge.y]) Q=PriorityQueue() Q.put([0,start])#[cost,x] while not Q.empty(): nowcost,nowx=Q.get() if mincost[nowx]==inf: mincost[nowx]=nowcost for cost,y in G[nowx]: newcost=nowcost+cost Q.put([newcost,y]) return mincost def warshallfloyd(edges,V): mincost=[[inf for b in range(V)] for a in range(V)] for a in range(V):mincost[a][a]=0 for edge in edges: mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する for k in range(V): for s in range(V): for t in range(V): if mincost[s][k]==inf or mincost[k][t]==inf:continue mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t]) return mincost def bellemanford(edges,V,start): mincost=[inf]*V mincost[start]=0 for _ in range(V): for edge in edges: if mincost[edge.x]==inf:continue mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val) return mincost def getmd(x1,y1,x2,y2): return abs(x1-x2)+abs(y1-y2) def geted(x1,y1,x2,y2): return math.sqrt((x1-x2)**2+(y1-y2)**2) class fordfulkerson(): def __init__(self,edges,V,s,t): self.V=V self.used=[False]*V self.G=[[] for a in range(V)] self.s=s self.t=t for edge in edges: self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])}) self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1}) def dfs(self,v,t,f=inf): if v==t:return f self.used[v]=True for a in range(len(self.G[v])): x=self.G[v][a]["x"] y=self.G[v][a]["y"] cap=self.G[v][a]["cap"] rev=self.G[y][self.G[x][a]["rev"]] if self.used[y] or cap==0:continue f2=self.dfs(y,t,min(f,cap)) if f2>0: self.G[v][a]["cap"]-=f2 rev["cap"]+=f2 return f2 return 0 def maxflow(self): flow=0 while True: self.used=[False]*V zouka=self.dfs(self.s,self.t) if zouka==0:break flow+=zouka return flow def heron(a,b,c): s=(a+b+c)/2 S=s(s-a)(s-b)(a-c) S=math.sqrt(S) return S def getAreaOfTriangle(x1,y1,x2,y2,x3,y3): a=geted(x1,y1,x2,y2) b=geted(x2,y2,x3,y3) c=geted(x3,y3,x1,y1) return heron(a,b,c) ###################################################################################################### N,K=inputintlist() A=inputintlist() K=min(K,43) for k in range(K): imos=[0]*(N) for a in range(len(A)): mmin=max(a-A[a],0) mmax=min(a+A[a],N-1) imos[mmin]+=1 if mmax!=N-1:imos[mmax+1]-=1 A=list(accumulate(imos)) print((join(A)))
# coding: utf-8 #import numpy as np import re import math from collections import defaultdict from collections import deque import collections from fractions import Fraction import bisect from queue import PriorityQueue import itertools from itertools import accumulate from copy import deepcopy import random import time import os import sys import datetime from functools import lru_cache from functools import reduce readline=sys.stdin.readline sys.setrecursionlimit(2000000) alphabet="abcdefghijklmnopqrstuvwxyz" numbers="0123456789" mod=int(10**9+7) inf=int(10**19) class Edge(): def __init__(self,x,y,val=1): self.x=x self.y=y self.val=val class unionfind(): def __init__(self,n): self.n=n self.P=[a for a in range(n)] self.rank=[0]*n def find(self,x): if(x!=self.P[x]): self.P[x]=self.find(self.P[x]) return self.P[x] def same(self,x,y): return self.find(x)==self.find(y) def link(self,x,y): if self.rank[x]<self.rank[y]: self.P[x]=y elif self.rank[y]<self.rank[x]: self.P[y]=x else: self.P[x]=y self.rank[y]+=1 def unite(self,x,y): self.link(self.find(x),self.find(y)) def size(self): S=set() for a in range(self.n): S.add(self.find(a)) return len(S) def yn(b): if b:print("yes") else:print("no") def Yn(b): if b:print("Yes") else:print("No") def YN(b): if b:print("YES") else:print("NO") def ispow(a,b): now=b while now<a: now*=b return now==a def getbin(num,size): A=[0]*size for a in range(size): if (num>>(size-a-1))&1==1: A[a]=1 else: A[a]=0 return A def getfacs(n,mod_=0): A=[1]*(n+1) for a in range(2,len(A)): A[a]=A[a-1]*a if(mod_>0):A[a]%=mod_ return A def comb(n,r,mod,fac): if(n-r<0):return 0 return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod def nextcomb(num,size): x=num&(-num) y=num+x z=num&(~y) z//=x z=z>>1 num=(y|z) if(num>=(1<<size)):return False else:return num def getprimes(n): if n==0:return [] A=[True]*(n+1) A[0]=False A[1]=False for a in range(2,n+1): if A[a]: for b in range(a*2,n+1,a): A[b]=False ret=[] for a in range(n+1): if(A[a]):ret.append(a) return ret def isprime(num): if(num<=1):return False i=2 while i*i<=num: if(num%i==0):return False i+=1 return True def ifelse(bbool,ret1,ret2): if bbool:return ret1 else:return ret2 def join(A,c=" "): n=len(A) A=list(map(str,A)) s="" for a in range(n): s+=A[a] if(a<n-1):s+=c return s def factorize(n): b = 2 ret=defaultdict(int) while b * b <= n: while n % b == 0: n //= b ret[b]+=1 b+=1 if n > 1:ret[n]+=1 return ret def pm(x): return x//abs(x) def inputintlist(): return list(map(int,input().split())) def inputfloatlist(): return list(map(float,input().split())) def tozero(A): ret=[None]*len(A) for a in range(len(A)): ret[a]=A[a]-1 return ret def istanchouzouka(A): f=True prev=min(A)-1 for a in A: if prev>=a: f=False prev=a return f def istanchouhigensyou(A): f=True prev=min(A)-1 for a in A: if prev>a: f=False prev=a return f def getallsum(A): s=sum(A) dp=defaultdict(int) dp[0]=1 for a in range(0,len(A)): for b in range(s,-1,-1): if b-A[a]>=0: dp[b]+=dp[b-A[a]] return dp def yuukoutomukou(edges): ret=deepcopy(edges) for edge in edges: if not edge.x==edge.y: ret.append(Edge(edge.y,edge.x,edge.val)) return ret def dijkstra(edges,V,start): mincost=[inf]*V G=[[] for a in range(V)] for edge in edges: G[edge.x].append([edge.val,edge.y]) Q=PriorityQueue() Q.put([0,start])#[cost,x] while not Q.empty(): nowcost,nowx=Q.get() if mincost[nowx]==inf: mincost[nowx]=nowcost for cost,y in G[nowx]: newcost=nowcost+cost Q.put([newcost,y]) return mincost def warshallfloyd(edges,V): mincost=[[inf for b in range(V)] for a in range(V)] for a in range(V):mincost[a][a]=0 for edge in edges: mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する for k in range(V): for s in range(V): for t in range(V): if mincost[s][k]==inf or mincost[k][t]==inf:continue mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t]) return mincost def bellemanford(edges,V,start): mincost=[inf]*V mincost[start]=0 for _ in range(V): for edge in edges: if mincost[edge.x]==inf:continue mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val) return mincost def getmd(x1,y1,x2,y2): return abs(x1-x2)+abs(y1-y2) def geted(x1,y1,x2,y2): return math.sqrt((x1-x2)**2+(y1-y2)**2) class fordfulkerson(): def __init__(self,edges,V,s,t): self.V=V self.used=[False]*V self.G=[[] for a in range(V)] self.s=s self.t=t for edge in edges: self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])}) self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1}) def dfs(self,v,t,f=inf): if v==t:return f self.used[v]=True for a in range(len(self.G[v])): x=self.G[v][a]["x"] y=self.G[v][a]["y"] cap=self.G[v][a]["cap"] rev=self.G[y][self.G[x][a]["rev"]] if self.used[y] or cap==0:continue f2=self.dfs(y,t,min(f,cap)) if f2>0: self.G[v][a]["cap"]-=f2 rev["cap"]+=f2 return f2 return 0 def maxflow(self): flow=0 while True: self.used=[False]*V zouka=self.dfs(self.s,self.t) if zouka==0:break flow+=zouka return flow def heron(a,b,c): s=(a+b+c)/2 S=s(s-a)(s-b)(a-c) S=math.sqrt(S) return S def getAreaOfTriangle(x1,y1,x2,y2,x3,y3): a=geted(x1,y1,x2,y2) b=geted(x2,y2,x3,y3) c=geted(x3,y3,x1,y1) return heron(a,b,c) ###################################################################################################### N, K = list(map(int,input().split())) A = list(map(int,input().split())) K=min(K,43) for k in range(K): imos=[0]*(N) for a in range(len(A)): mmin=max(a-A[a],0) mmax=min(a+A[a],N-1) imos[mmin]+=1 if mmax!=N-1:imos[mmax+1]-=1 A=list(accumulate(imos)) print((" ".join(list(map(str,A)))))
p02647
# coding: utf-8 #import numpy as np import re import math from collections import defaultdict from collections import deque import collections from fractions import Fraction import bisect from queue import PriorityQueue import itertools from itertools import accumulate from copy import deepcopy import random import time import os import sys import datetime from functools import lru_cache from functools import reduce readline=sys.stdin.readline sys.setrecursionlimit(2000000) alphabet="abcdefghijklmnopqrstuvwxyz" numbers="0123456789" mod=int(10**9+7) inf=int(10**19) class Edge(): def __init__(self,x,y,val=1): self.x=x self.y=y self.val=val class unionfind(): def __init__(self,n): self.n=n self.P=[a for a in range(n)] self.rank=[0]*n def find(self,x): if(x!=self.P[x]): self.P[x]=self.find(self.P[x]) return self.P[x] def same(self,x,y): return self.find(x)==self.find(y) def link(self,x,y): if self.rank[x]<self.rank[y]: self.P[x]=y elif self.rank[y]<self.rank[x]: self.P[y]=x else: self.P[x]=y self.rank[y]+=1 def unite(self,x,y): self.link(self.find(x),self.find(y)) def size(self): S=set() for a in range(self.n): S.add(self.find(a)) return len(S) def yn(b): if b:print("yes") else:print("no") def Yn(b): if b:print("Yes") else:print("No") def YN(b): if b:print("YES") else:print("NO") def ispow(a,b): now=b while now<a: now*=b return now==a def getbin(num,size): A=[0]*size for a in range(size): if (num>>(size-a-1))&1==1: A[a]=1 else: A[a]=0 return A def getfacs(n,mod_=0): A=[1]*(n+1) for a in range(2,len(A)): A[a]=A[a-1]*a if(mod_>0):A[a]%=mod_ return A def comb(n,r,mod,fac): if(n-r<0):return 0 return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod def nextcomb(num,size): x=num&(-num) y=num+x z=num&(~y) z//=x z=z>>1 num=(y|z) if(num>=(1<<size)):return False else:return num def getprimes(n): if n==0:return [] A=[True]*(n+1) A[0]=False A[1]=False for a in range(2,n+1): if A[a]: for b in range(a*2,n+1,a): A[b]=False ret=[] for a in range(n+1): if(A[a]):ret.append(a) return ret def isprime(num): if(num<=1):return False i=2 while i*i<=num: if(num%i==0):return False i+=1 return True def ifelse(bbool,ret1,ret2): if bbool:return ret1 else:return ret2 def join(A,c=" "): n=len(A) A=list(map(str,A)) s="" for a in range(n): s+=A[a] if(a<n-1):s+=c return s def factorize(n): b = 2 ret=defaultdict(int) while b * b <= n: while n % b == 0: n //= b ret[b]+=1 b+=1 if n > 1:ret[n]+=1 return ret def pm(x): return x//abs(x) def inputintlist(): return list(map(int,input().split())) def inputfloatlist(): return list(map(float,input().split())) def tozero(A): ret=[None]*len(A) for a in range(len(A)): ret[a]=A[a]-1 return ret def istanchouzouka(A): f=True prev=min(A)-1 for a in A: if prev>=a: f=False prev=a return f def istanchouhigensyou(A): f=True prev=min(A)-1 for a in A: if prev>a: f=False prev=a return f def getallsum(A): s=sum(A) dp=defaultdict(int) dp[0]=1 for a in range(0,len(A)): for b in range(s,-1,-1): if b-A[a]>=0: dp[b]+=dp[b-A[a]] return dp def yuukoutomukou(edges): ret=deepcopy(edges) for edge in edges: if not edge.x==edge.y: ret.append(Edge(edge.y,edge.x,edge.val)) return ret def dijkstra(edges,V,start): mincost=[inf]*V G=[[] for a in range(V)] for edge in edges: G[edge.x].append([edge.val,edge.y]) Q=PriorityQueue() Q.put([0,start])#[cost,x] while not Q.empty(): nowcost,nowx=Q.get() if mincost[nowx]==inf: mincost[nowx]=nowcost for cost,y in G[nowx]: newcost=nowcost+cost Q.put([newcost,y]) return mincost def warshallfloyd(edges,V): mincost=[[inf for b in range(V)] for a in range(V)] for a in range(V):mincost[a][a]=0 for edge in edges: mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する for k in range(V): for s in range(V): for t in range(V): if mincost[s][k]==inf or mincost[k][t]==inf:continue mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t]) return mincost def bellemanford(edges,V,start): mincost=[inf]*V mincost[start]=0 for _ in range(V): for edge in edges: if mincost[edge.x]==inf:continue mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val) return mincost def getmd(x1,y1,x2,y2): return abs(x1-x2)+abs(y1-y2) def geted(x1,y1,x2,y2): return math.sqrt((x1-x2)**2+(y1-y2)**2) class fordfulkerson(): def __init__(self,edges,V,s,t): self.V=V self.used=[False]*V self.G=[[] for a in range(V)] self.s=s self.t=t for edge in edges: self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])}) self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1}) def dfs(self,v,t,f=inf): if v==t:return f self.used[v]=True for a in range(len(self.G[v])): x=self.G[v][a]["x"] y=self.G[v][a]["y"] cap=self.G[v][a]["cap"] rev=self.G[y][self.G[x][a]["rev"]] if self.used[y] or cap==0:continue f2=self.dfs(y,t,min(f,cap)) if f2>0: self.G[v][a]["cap"]-=f2 rev["cap"]+=f2 return f2 return 0 def maxflow(self): flow=0 while True: self.used=[False]*V zouka=self.dfs(self.s,self.t) if zouka==0:break flow+=zouka return flow def heron(a,b,c): s=(a+b+c)/2 S=s(s-a)(s-b)(a-c) S=math.sqrt(S) return S def getAreaOfTriangle(x1,y1,x2,y2,x3,y3): a=geted(x1,y1,x2,y2) b=geted(x2,y2,x3,y3) c=geted(x3,y3,x1,y1) return heron(a,b,c) ###################################################################################################### N, K = list(map(int,input().split())) A = list(map(int,input().split())) K=min(K,43) for k in range(K): imos=[0]*(N) for a in range(len(A)): mmin=max(a-A[a],0) mmax=min(a+A[a],N-1) imos[mmin]+=1 if mmax!=N-1:imos[mmax+1]-=1 A=list(accumulate(imos)) print((" ".join(list(map(str,A)))))
# coding: utf-8 #import numpy as np import re import math from collections import defaultdict from collections import deque import collections from fractions import Fraction import bisect from queue import PriorityQueue import itertools from itertools import accumulate from copy import deepcopy import random import time import os import sys import datetime from functools import lru_cache from functools import reduce readline=sys.stdin.readline sys.setrecursionlimit(2000000) alphabet="abcdefghijklmnopqrstuvwxyz" numbers="0123456789" mod=int(10**9+7) inf=int(10**19) class Edge(): def __init__(self,x,y,val=1): self.x=x self.y=y self.val=val class unionfind(): def __init__(self,n): self.n=n self.P=[a for a in range(n)] self.rank=[0]*n def find(self,x): if(x!=self.P[x]): self.P[x]=self.find(self.P[x]) return self.P[x] def same(self,x,y): return self.find(x)==self.find(y) def link(self,x,y): if self.rank[x]<self.rank[y]: self.P[x]=y elif self.rank[y]<self.rank[x]: self.P[y]=x else: self.P[x]=y self.rank[y]+=1 def unite(self,x,y): self.link(self.find(x),self.find(y)) def size(self): S=set() for a in range(self.n): S.add(self.find(a)) return len(S) def yn(b): if b:print("yes") else:print("no") def Yn(b): if b:print("Yes") else:print("No") def YN(b): if b:print("YES") else:print("NO") def ispow(a,b): now=b while now<a: now*=b return now==a def getbin(num,size): A=[0]*size for a in range(size): if (num>>(size-a-1))&1==1: A[a]=1 else: A[a]=0 return A def getfacs(n,mod_=0): A=[1]*(n+1) for a in range(2,len(A)): A[a]=A[a-1]*a if(mod_>0):A[a]%=mod_ return A def comb(n,r,mod,fac): if(n-r<0):return 0 return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod def nextcomb(num,size): x=num&(-num) y=num+x z=num&(~y) z//=x z=z>>1 num=(y|z) if(num>=(1<<size)):return False else:return num def getprimes(n): if n==0:return [] A=[True]*(n+1) A[0]=False A[1]=False for a in range(2,n+1): if A[a]: for b in range(a*2,n+1,a): A[b]=False ret=[] for a in range(n+1): if(A[a]):ret.append(a) return ret def isprime(num): if(num<=1):return False i=2 while i*i<=num: if(num%i==0):return False i+=1 return True def ifelse(bbool,ret1,ret2): if bbool:return ret1 else:return ret2 def join(A,c=" "): n=len(A) A=list(map(str,A)) s="" for a in range(n): s+=A[a] if(a<n-1):s+=c return s def factorize(n): b = 2 ret=defaultdict(int) while b * b <= n: while n % b == 0: n //= b ret[b]+=1 b+=1 if n > 1:ret[n]+=1 return ret def pm(x): return x//abs(x) def inputintlist(): return list(map(int,input().split())) def inputfloatlist(): return list(map(float,input().split())) def tozero(A): ret=[None]*len(A) for a in range(len(A)): ret[a]=A[a]-1 return ret def istanchouzouka(A): f=True prev=min(A)-1 for a in A: if prev>=a: f=False prev=a return f def istanchouhigensyou(A): f=True prev=min(A)-1 for a in A: if prev>a: f=False prev=a return f def getallsum(A): s=sum(A) dp=defaultdict(int) dp[0]=1 for a in range(0,len(A)): for b in range(s,-1,-1): if b-A[a]>=0: dp[b]+=dp[b-A[a]] return dp def yuukoutomukou(edges): ret=deepcopy(edges) for edge in edges: if not edge.x==edge.y: ret.append(Edge(edge.y,edge.x,edge.val)) return ret def dijkstra(edges,V,start): mincost=[inf]*V G=[[] for a in range(V)] for edge in edges: G[edge.x].append([edge.val,edge.y]) Q=PriorityQueue() Q.put([0,start])#[cost,x] while not Q.empty(): nowcost,nowx=Q.get() if mincost[nowx]==inf: mincost[nowx]=nowcost for cost,y in G[nowx]: newcost=nowcost+cost Q.put([newcost,y]) return mincost def warshallfloyd(edges,V): mincost=[[inf for b in range(V)] for a in range(V)] for a in range(V):mincost[a][a]=0 for edge in edges: mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する for k in range(V): for s in range(V): for t in range(V): if mincost[s][k]==inf or mincost[k][t]==inf:continue mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t]) return mincost def bellemanford(edges,V,start): mincost=[inf]*V mincost[start]=0 for _ in range(V): for edge in edges: if mincost[edge.x]==inf:continue mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val) return mincost def getmd(x1,y1,x2,y2): return abs(x1-x2)+abs(y1-y2) def geted(x1,y1,x2,y2): return math.sqrt((x1-x2)**2+(y1-y2)**2) class fordfulkerson(): def __init__(self,edges,V,s,t): self.V=V self.used=[False]*V self.G=[[] for a in range(V)] self.s=s self.t=t for edge in edges: self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])}) self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1}) def dfs(self,v,t,f=inf): if v==t:return f self.used[v]=True for a in range(len(self.G[v])): x=self.G[v][a]["x"] y=self.G[v][a]["y"] cap=self.G[v][a]["cap"] rev=self.G[y][self.G[x][a]["rev"]] if self.used[y] or cap==0:continue f2=self.dfs(y,t,min(f,cap)) if f2>0: self.G[v][a]["cap"]-=f2 rev["cap"]+=f2 return f2 return 0 def maxflow(self): flow=0 while True: self.used=[False]*V zouka=self.dfs(self.s,self.t) if zouka==0:break flow+=zouka return flow def heron(a,b,c): s=(a+b+c)/2 S=s(s-a)(s-b)(a-c) S=math.sqrt(S) return S def getAreaOfTriangle(x1,y1,x2,y2,x3,y3): a=geted(x1,y1,x2,y2) b=geted(x2,y2,x3,y3) c=geted(x3,y3,x1,y1) return heron(a,b,c) ###################################################################################################### N, K = inputintlist() A = inputintlist() K=min(K,43) for k in range(K): imos=[0]*(N) for a in range(len(A)): mmin=max(a-A[a],0) mmax=min(a+A[a],N-1) imos[mmin]+=1 if mmax!=N-1:imos[mmax+1]-=1 A=list(accumulate(imos)) print((" ".join(list(map(str,A)))))
p02647
n, k = list(map(int, input().split())) As = list(map(int, input().split())) def change(arr): newAs = [0] * n for i, a in enumerate(arr): for t in range(max(i - a, 0), min(i + a + 1, n)): newAs[t] += 1 return newAs for temp in range(min(k, 40)): As = change(As) print((' '.join(map(str, As))))
import math from itertools import accumulate n, k = list(map(int, input().split())) As = list(map(int, input().split())) for i in range(min(41, k)): _As = [0]*(n+1) for j in range(n): l = max(0, j - As[j]) r = min(n - 1, j + As[j]) _As[l] += 1 _As[r+1] -= 1 As = list(accumulate(_As))[:-1] print((' '.join([str(A) for A in As])))
p02647
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): B = [0 for i in range(N)] 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) A = B.copy() if _ > 2 * int(sqrt(N)): break L = " ".join([str(x) for x in A]) print(L)
from copy import copy, deepcopy from collections import Counter from math import sqrt, floor, factorial, log 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): B = [0 for i in range(N)] for i in range(N): B[max(i-A[i], 0)] += 1 idx = min(i+A[i]+1, N) if idx != N: B[idx] -= 1 # print(B) for i in range(N-1): B[i+1] += B[i] # print(B) A = B.copy() if _ > 10 * int(log(N)): break L = " ".join([str(x) for x in A]) print(L)
p02647
import math from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) for _ in range(k): l = [] b = [0]*n for i in range(1, n+1): x = math.ceil(i-a[i-1]-0.5) y = math.floor(i+a[i-1]+0.5) l += list(range(x, y+1)) c = Counter(l) for num in range(n): b[num] = c[num+1] a = b print((' '.join(map(str, b))))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) for _ in range(k): l = [] b = [0]*n for i in range(1, n+1): x = i-a[i-1]-0.5 y = i+a[i-1]+0.5 l.append([x, y]) for j in range(1, n+1): for x, y in l: if x <= j <= y: b[j-1] += 1 a = b print((' '.join(map(str, b))))
p02647
N, W = list(map(int, input().split())) dp = [0]*(W+1) max_weight = 0 for i in range(N): v, w, m = list(map(int, input().split())) n = 1 while m > 0: m -= n _v, _w = v*n, w*n max_weight = min(W, max_weight + _w) for k in range(max_weight, _w-1, -1): if dp[k] < dp[k-_w] + _v: dp[k] = dp[k-_w] + _v n = m if n << 1 > m else n << 1 print((max(dp)))
N, W = list(map(int, input().split())) dp = [0]*(W+1) max_w = 0 for i in range(N): v, w, m = list(map(int, input().split())) n = 1 while m > 0: m -= n _v, _w = v*n, w*n max_w = W if max_w+_w > W else max_w+_w for k in range(max_w, _w-1, -1): if dp[k] < dp[k-_w] + _v: dp[k] = dp[k-_w] + _v n = m if n << 1 > m else n << 1 print((max(dp)))
p02320
n, w = list(map(int, input().split())) value = [] weight = [] num = [] for _ in range(n): vi, wi, ni = list(map(int, input().split())) value.append(vi) weight.append(wi) num.append(ni) def to_digit(x): acc = 1 ret = [0] while x >= acc: ret.append(acc) x -= acc acc *= 2 if x: ret.append(x) return ret num = list(map(to_digit, num)) dp = [0 for _ in range(w + 1)] for i in range(n): vi = value[i] wi = weight[i] numsi = num[i] for k in numsi: for j in range(w, -1, -1): if j >= wi * k: dp[j] = max(dp[j], dp[j - wi * k] + vi * k) print((dp[w]))
def main(): n, w = list(map(int, input().split())) value = [] weight = [] num = [] for _ in range(n): vi, wi, ni = list(map(int, input().split())) value.append(vi) weight.append(wi) num.append(ni) def to_digit(x): acc = 1 ret = [0] while x >= acc: ret.append(acc) x -= acc acc *= 2 if x: ret.append(x) return ret num = list(map(to_digit, num)) dp = [0 for _ in range(w + 1)] for i in range(n): vi = value[i] wi = weight[i] numsi = num[i] for k in numsi: wik = wi * k vik = vi * k for j in range(w, wik - 1, -1): dp[j] = max(dp[j], dp[j - wik] + vik) print((dp[w])) main()
p02320
n, knapsack = list(map(int, input().split())) dp = [-1] * (knapsack + 1) dp[0] = 0 for _ in range(n): value, weight, amount = list(map(int, input().split())) for i in range(knapsack - weight, -1, -1): if dp[i] < 0: continue for j in range(1, amount + 1): new_index = i + weight * j if new_index > knapsack: continue new_value = dp[i] + value * j if dp[new_index] < new_value: dp[new_index] = new_value print((max(dp)))
n, knapsack = list(map(int, input().split())) dp = [-1] * (knapsack + 1) dp[0] = 0 for _ in range(n): value, weight, amount = list(map(int, input().split())) for i in range(knapsack - weight, -1, -1): if dp[i] < 0: continue for j in range(1, amount + 1): new_index = i + weight * j if new_index > knapsack: break new_value = dp[i] + value * j if dp[new_index] < new_value: dp[new_index] = new_value print((max(dp)))
p02320
n, knapsack = list(map(int, input().split())) dp = [-1] * (knapsack + 1) dp[0] = 0 for _ in range(n): value, weight, amount = list(map(int, input().split())) for i in range(knapsack - weight, -1, -1): if dp[i] < 0: continue for j in range(1, amount + 1): new_index = i + weight * j if new_index > knapsack: break new_value = dp[i] + value * j if dp[new_index] < new_value: dp[new_index] = new_value print((max(dp)))
n, knapsack = list(map(int, input().split())) dp = [-1] * (knapsack + 1) dp[0] = 0 items = [list(map(int, input().split())) for _ in range(n)] for value, weight, amount in items: k = 0 while amount: take = min(amount, 1 << k) amount -= take gv, gw = value * take, weight * take for i in range(knapsack - gw, -1, -1): if dp[i] < 0: continue new_value = dp[i] + gv if dp[i + gw] < new_value: dp[i + gw] = new_value k += 1 print((max(dp)))
p02320
n, knapsack = list(map(int, input().split())) dp = [-1] * (knapsack + 1) dp[0] = 0 items = [list(map(int, input().split())) for _ in range(n)] for value, weight, amount in items: k = 0 while amount: take = 1 << k if take > amount: take = amount amount -= take gv, gw = value * take, weight * take for i in range(knapsack - gw, -1, -1): dpi = dp[i] if dpi < 0: continue new_value = dpi + gv if dp[i + gw] < new_value: dp[i + gw] = new_value k += 1 print((max(dp)))
n, knapsack = list(map(int, input().split())) dp = [-1] * (knapsack + 1) dp[0] = 0 items = [list(map(int, input().split())) for _ in range(n)] for value, weight, amount in items: k = 0 while amount: take = 1 << k if take > amount: take = amount amount -= take gv, gw = value * take, weight * take if gw > knapsack: break for i, dpi in enumerate(dp[knapsack - gw::-1]): if dpi < 0: continue new_value = dpi + gv if dp[knapsack - i] < new_value: dp[knapsack - i] = new_value k += 1 print((max(dp)))
p02320
while 1: n=int(eval(input())) if not n:break f=1 L={} for a,b,c in [list(map(int,input().split())) for i in range(n)]: a=str(a) d=b*c if a in L: if L[a]>=1e6:continue L[a]+=d else:L[a]=d if L[a] >= 1e6: print(a) f=0 if f:print('NA')
while 1: n=int(eval(input())) if not n:break f=1 L={} for a,b,c in [input().split() for i in range(n)]: d=int(b)*int(c) if a in L: if L[a]>=1e6:continue L[a]+=d else:L[a]=d if L[a]>=1e6: print(a) f=0 if f:print('NA')
p00100
# coding: utf-8 # Here your code ! employeeSalesList = [] def resetDataset(): del employeeSalesList[0 : len(employeeSalesList) + 1] def readDataCount(): return int(eval(input())) def searchEmployeeSales(employeeId): for data in employeeSalesList: if data[0] == employeeId: return data newData = [employeeId, 0] employeeSalesList.append(newData) return newData answerList = [] def printEmployeeOfDataset(): found = False for data in employeeSalesList: if data[1] >= 1000000: answerList.append(data[0]) found = True if not found: answerList.append("NA") resetDataset() dataCount = readDataCount() while dataCount > 0: for _ in range(dataCount): employeeId, price, volume = list(map(int, input().split(" "))) employeeSales = searchEmployeeSales(employeeId) employeeSales[1] += price * volume printEmployeeOfDataset() resetDataset() dataCount = readDataCount() for row in answerList: print(row)
# coding: utf-8 # Here your code ! employeeSalesList = [] def resetDataset(): del employeeSalesList[0 : len(employeeSalesList) + 1] def readDataCount(): return int(eval(input())) def searchEmployeeSales(employeeId): for data in employeeSalesList: if data[0] == employeeId: return data newData = [employeeId, 0] employeeSalesList.append(newData) return newData def printEmployeeOfDataset(): answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000] if len(answerList) == 0: print("NA") else: print(("\n".join(map(str, answerList)))) resetDataset() dataCount = readDataCount() while dataCount > 0: for _ in range(dataCount): employeeId, price, volume = list(map(int, input().split(" "))) employeeSales = searchEmployeeSales(employeeId) employeeSales[1] += price * volume printEmployeeOfDataset() resetDataset() dataCount = readDataCount()
p00100
n = int(eval(input())) li = [int(x) for x in input().split()] X = sum(li) ans = 100000000000 lix = [] for i in range(n-1): lix = li[:i+1] ans =min(ans ,abs(X - sum(lix)*2)) print(ans)
from itertools import accumulate n = int(eval(input())) li = [int(x) for x in input().split()] X = list(accumulate(li)) ans = float("inf") for i in range(n-1): ans =min(ans ,abs(X[-1] - X[i]*2)) print(ans)
p03659
n=int(eval(input())) a=list(map(int,input().split())) sa=sum(a) hantei=2*(10**9)+1 sx=0 for i in range(len(a)-1): sx+=a[i] if abs(sa-2*sx)<hantei: hantei=abs(sa-2*sx) print(hantei)
n=int(eval(input())) #a,b=map(int,input().split()) a=list(map(int,input().split())) #n=int(input()) #s=input() sa=sum(a) ans=10**10+1 x=0 for i in range(0,n-1): x+=a[i] if abs(2*x-sa)<ans: ans=abs(2*x-sa) print(ans)
p03659
def main(): n = int(eval(input())) a = [int(x) for x in input().split()] for i in range(1, n): a[i] += a[i - 1] answer = float("inf") for i in range(n - 1): answer = min(answer, abs(a[-1] - 2 * a[i])) print(answer) if __name__ == '__main__': main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) for i in range(1, n): a[i] += a[i - 1] ans = float("inf") for i in range(n - 1): ans = min(ans, abs(a[-1] - 2 * a[i])) print(ans) if __name__ == '__main__': main()
p03659
N = int(eval(input())) A = list(map(int, input().split())) ans = abs(A[0] - sum(A[1:])) for i in range(1, N-1): ans = min(abs(sum(A[:i]) - sum(A[i:])), ans) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) X = sum(A) xi = A[0] ans = abs(X - 2 * A[N-1]) for i in range(1, N-1): xi += A[i] ans = min(abs(X - 2 * xi), ans) print(ans)
p03659
n=int(eval(input())) a=list(map(int,input().split())) s=sum(a) mi=10**15 for i in range(1,len(a)): s1=sum(a[0:i]) s2=s-s1 #print(s1,s2) mi=min([mi,abs(s1-s2)]) print(mi)
import sys n=int(eval(input())) a=list(map(int,input().split())) s=sum(a) if(n==2): mi=abs(a[0]-a[1]) else: mi=10**15 s1=a[0] for i in range(1,len(a)-1): s1+=a[i] s2=s-s1 #print(s1,s2) mi=min([mi,abs(s1-s2)]) print(mi)
p03659
n = int(eval(input())) a = list(map(int,input().split())) ans = float("Inf") for i in range(1,n): ans = min(ans,abs(sum(a[:i])-sum(a[i:]))) print(ans)
n = int(eval(input())) a = list(map(int,input().split())) b = sum(a) c = 0 ans = float("Inf") for i in range(n-1): c += a[i] b -= a[i] ans = min(ans,abs(b-c)) print(ans)
p03659
n = int(eval(input())) a = list(map(int, input().split())) total = sum(a) ans = float("inf") for i in range(n-1): x = sum(a[:i+1]) y = total - x if(abs(x-y) < ans): ans = abs(x-y) print(ans)
n = int(eval(input())) a = list(map(int, input().split())) total = sum(a) x = 0 ans = float("inf") for i in range(n-1): x += a[i] y = total - x if(abs(x-y) < ans): ans = abs(x-y) print(ans)
p03659
from itertools import accumulate eval(input()) a = list(map(int, input().split())) b = list(accumulate(a)) c = [abs(y * 2 - b[-1]) for y in b][:-1] print((min([abs(y * 2 - b[-1]) for y in b][:-1])))
from itertools import accumulate eval(input()) a = list(map(int, input().split())) b = list(accumulate(a)) print((min([abs(y * 2 - b[-1]) for y in b][:-1])))
p03659
N = int(eval(input())) A = list(map(int,input().split())) B = [] for i in range(1,N): a = sum(A[:i]) b = sum(A[i:]) B.append(abs(a-b)) print((min(B)))
N = int(eval(input())) A = list(map(int,input().split())) sum_A = sum(A) ans = 10**20 X = 0 for a in A[:-1]: X += a ans = min(ans,abs(sum_A-2*X)) print(ans)
p03659
n=int(eval(input())) a=list(map(int,input().split())) ans=[] for i in range(1,n): x=sum(a[0:i]) y=sum(a[i:]) ans.append(abs(x-y)) print((min(ans)))
n=int(eval(input())) a=list(map(int,input().split())) total=sum(a) ans=[] x=0 for i in range(n-1): x+=a[i] y=total-x ans.append(abs(x-y)) print((min(ans)))
p03659
import sys def input(): return sys.stdin.readline().strip() def resolve(): from itertools import accumulate N = int(eval(input())) # len(A) A = list(map(int, input().split())) B = [0] + A B = list(accumulate(B)) # 累積和を格納したリスト作成 # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り ans=10**18 for i in range(1, N): snuke=B[i] araiguma=sum(A)-B[i] ans=min(ans,abs(snuke-araiguma)) print(ans) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): from itertools import accumulate N = int(eval(input())) # len(A) A = list(map(int, input().split())) B = [0] + A B = list(accumulate(B)) # 累積和を格納したリスト作成 ans=10**18 for i in range(1, N): snuke=B[i] araiguma=B[N]-B[i] ans=min(ans,abs(snuke-araiguma)) print(ans) resolve()
p03659
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math N = int(eval(input())) a = [int(i) for i in input().split()] sum_a = sum(a) ans = 10**10 for i in range(1,N): x = sum(a[:i]) ans = min(ans,abs(sum_a-2*x)) print(ans)
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math N = int(eval(input())) a = [int(i) for i in input().split()] sum_a = sum(a) ans = 10**10 x = 0 for i in range(N-1): x += a[i] ans = min(ans,abs(sum_a-2*x)) print(ans)
p03659
N = int(eval(input())) A = list(map(int, input().split())) s = [] for i in range(1, N): s.append(abs(sum(A[0:i]) - sum(A[i:]))) print((min(s)))
N = int(eval(input())) A = list(map(int, input().split())) ans = float('inf') snu = 0 ara = sum(A) for a in A[0:-1]: snu += a ara -= a ans = min(ans, abs(snu - ara)) print(ans)
p03659