QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#765556 | #5460. Sum of Numbers | O_start# | RE | 13ms | 10568kb | Python3 | 1.8kb | 2024-11-20 14:38:50 | 2024-11-20 14:38:56 |
Judging History
answer
t = int(input())
n, k = 0, 0
s = ''
d = 10
def solve():
len0 = n // (k + 1)
pos0 = [len0 * i + len0 - 1 for i in range(k)]
dp = [[-1 for i in range(d * 2)] for _ in range(k)]
for i in range(k):
if i == 0:
for j in range(d * 2):
p1 = pos0[i] + (j - d)
if p1 < 0 or p1 >= n:
continue
dp[i][j] = int(s[0: p1 + 1])
continue
for j in range(d * 2):
for pre_j in range(d * 2):
p1 = pos0[i] + (j - d)
pre_p1 = pos0[i - 1] + (pre_j - d)
if p1 < 0 or p1 >= n:
continue
if pre_p1 < 0 or pre_p1 >= n:
continue
if not pre_p1 < p1:
continue
if dp[i - 1][pre_j] == -1:
continue
temp = dp[i - 1][pre_j] + int(s[pre_p1 + 1: p1 + 1])
# dp[i][j] = temp if dp[i][j] == -1 or temp < dp[i][j] else -1
if dp[i][j] == -1:
dp[i][j] = temp
else:
dp[i][j] = min(dp[i][j], temp)
ans = -1
for pre_j in range(d * 2):
pre_p1 = pos0[len(pos0) - 1] + (pre_j - d)
if pre_p1 < 0 or pre_p1 >= n - 1:
continue
if dp[k - 1][pre_j] == -1:
continue
temp = dp[k - 1][pre_j] + int(s[pre_p1 + 1:])
if ans == -1:
ans = temp
else:
ans = min(ans, temp)
# for i in range(k):
# print(dp[i])
print(ans)
for _ in range(t):
ins = input().split(' ')
n, k = int(ins[0]), int(ins[1])
s = input()
solve()
'''
1
8 1
45455151
'''
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 10568kb
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 1330897896655974774035586406544907434842835048336411271110427836483063457950873824562288934364096546537492367401...