QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88403#5460. Sum of NumbersYangmfRE 204ms51324kbPython31.5kb2023-03-16 10:07:262023-03-16 10:07:27

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-16 10:07:27]
  • 评测
  • 测评结果:RE
  • 用时:204ms
  • 内存:51324kb
  • [2023-03-16 10:07:26]
  • 提交

answer

# [n,k]=map(int(),input().split(' '))
# print(n,k)
global cnt
global n,k
cnt = 0
N = 200100
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(8000)]
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())
    num = input()
    ans = int(num)
    num='.'+num
    bk = n//(k+1)
    dfs(0,bk,0,k+1)
    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])//(10**(n-len-xx))
            # print((sum[len+1]-sum[len+xx+1]),(10**(n-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())
    for i in range(0,t):
        main()

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 204ms
memory: 51324kb

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

result: