QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692357#5460. Sum of NumbersEsoulingRE 26ms11888kbPython3887b2024-10-31 14:22:422024-10-31 14:22:42

Judging History

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

  • [2024-10-31 14:22:42]
  • 评测
  • 测评结果:RE
  • 用时:26ms
  • 内存:11888kb
  • [2024-10-31 14:22:42]
  • 提交

answer

import sys

sys.set_int_max_str_digits(100000)
t = int(input())
inf = int(int(1e5) * '1')

for tt in range(t):
    n, k = map(int, input().split())
    s = input()
    len = n // k
    r = n % len

    ans = 0
    cur = 0

    if n % (k + 1) == 0:
        len = n // (k + 1)
        while cur < n:
            ans += int(s[cur : cur + len])
            # print(cur, cur + len, s[cur : cur + len])
            cur += len
        print(ans)
        continue

    ans = inf
    for j in range(k + 1):
        cnt = 0
        temp = 0
        cur = 0
        while cur < n:
            if cnt == j:
                temp += int(s[cur : cur + r])
                cur += r
            else:
                temp += int(s[cur : cur + len])
                cur += len
            cnt += 1
        ans = min(ans, temp)

    print(ans)
                
    

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 26ms
memory: 11888kb

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:

2167772723973766429829905347034944442598176678780259844038180326126925462686305828895327994075214702316470280965931998428851486228090794221490968249044126316767641926361708582012167541015630903678931206608320090109104

result: