QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733422#5460. Sum of NumbersChensenCHX#RE 16ms10648kbPython31.0kb2024-11-10 18:47:582024-11-10 18:47:58

Judging History

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

  • [2024-11-10 18:47:58]
  • 评测
  • 测评结果:RE
  • 用时:16ms
  • 内存:10648kb
  • [2024-11-10 18:47:58]
  • 提交

answer

T = int(input())

globalcnt = 0
ansval = 0
seglen = 0
iptstr = ""
strlen = 0

lst = []
def dfs(remain):
    global ansval
    global globalcnt
    global seglen
    global iptstr
    global strlen

    if(remain == 0):
        cnt = 0
        for i in lst:
            cnt += i
        if(cnt == globalcnt):
            sums = 0
            st = 0
            for i in lst:
                #print(iptstr[st:st+seglen+i])
                sums += int(iptstr[st:min(st+seglen+i, strlen)])
                st += seglen+i
            ansval = min(ansval, sums)
        return;
    
    lst.append(1)
    dfs(remain-1)
    lst.pop()

    lst.append(0)
    dfs(remain-1)
    lst.pop()
    return;

while T != 0:
    T -= 1
    iptstr, k = input().split(' ')
    iptstr = input().split()[0]
    
    k = int(k)
    strlen = len(iptstr)
    seglen = strlen // (k+1)
    #print(strlen, k+1, seglen)

    globalcnt = strlen - (seglen * (k+1))
    ansval = int(iptstr)
    dfs(k+1)
    print(ansval)


    

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 10648kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Dangerous Syscalls

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255

result: