QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88390 | #5460. Sum of Numbers | Yangmf | RE | 184ms | 50508kb | Python3 | 1.5kb | 2023-03-16 09:38:19 | 2023-03-16 09:38:23 |
Judging History
answer
# [n,k]=map(int(),input().split(' '))
# print(n,k)
global cnt
global n,k
cnt = 0
N = 200010
dp = [[-1 for j in range(6+3)] for i in range(N)]
sum = [0 for i in range(N)]
dd = [0 for i in range(N)]
lens = [[-1 for j in range(8)] for i in range(800)]
tmp = [-1 for i in range(8)]
def get(l,r,num):
res = 0
for i in range(l,r+1):
res*=10
res+=int(num[i])
return res
def dfs(len,bk,d,mx):
global n, k
global cnt
if d>=mx:
if(len!=n):
return
cnt = cnt + 1
for i in range(mx):
lens[cnt][i] = tmp[i]
else :
for i in range(-1,2):
tmp[d] = bk+i
dfs(len+bk+i,bk,d+1,mx)
def main():
global n,k,cnt
cnt=0
n,k = map(int,input().split())
# print(n,k)
num = input()
ans = int(num)
# print(num)
num='.'+num
bk = n//(k+1)
dfs(0,bk,0,k+1)
# print(cnt)
dd[n]=1
dd[n+1]=1
for i in range(n,0,-1):
sum[i]=sum[i+1]+int(num[i])*dd[i]
dd[i-1]=dd[i]*10
for i in range(1,cnt+1):
res = 0
len = 0
for j in range(0,k+1):
xx = lens[i][j]
if(xx==0):
continue
res = res+(sum[len+1]-sum[len+xx+1])//dd[len+xx]
len += xx
ans=min(ans,res)
print(ans)
for i in range(0,n+3):
sum[i]=dd[i]=0
if __name__ == "__main__":
t = int(input())
while t!=0:
main()
t=t-1
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 184ms
memory: 50508kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255