QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103293#5460. Sum of NumbersAlpha_Q#RE 14ms8036kbPython3642b2023-05-05 04:16:072023-05-05 04:16:10

Judging History

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

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

answer

t = input()
while not t.strip():
  t = input()
t = int(t)
for _ in range(t):
  line = input()
  while not line.strip():
    line = input()
  n, k = map(int, line.split())
  s = input()
  n = len(s)
  while not s.strip():
    s = input()
  k = min(n, k + 1)
  same, extra = n // k, n % k
  ans = int(s)
  for mask in range(0, 1 << k):
    if bin(mask).count('1') != extra:
      continue
    sizes = [same] * k
    for i in range(0, k):
      if mask & 1 << i:
        sizes[i] += 1
    at, total = 0, 0
    for l in sizes:
      total += int(s[at : at + l])
      at += l
    ans = min(ans, total)
  print(ans)


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 8036kb

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: