QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#765646 | #5460. Sum of Numbers | O_start# | WA | 340ms | 13336kb | Python3 | 1.8kb | 2024-11-20 14:54:04 | 2024-11-20 14:54:07 |
Judging History
answer
import sys
sys.set_int_max_str_digits(0)
t = int(input())
n, k = 0, 0
s = ''
d = 5
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()
# for _ in range(n):
# s += '5'
solve()
'''
1
8 1
45455151
'''
詳細信息
Test #1:
score: 100
Accepted
time: 15ms
memory: 10612kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 340ms
memory: 13336kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
8778302828276641734101769772174890741123129798761536801300273231104957695424805626662888513684443618916335935333377754107701812746659030987748711697175018116713514562346659521304714090294 1330897896655974774035586406544907434842835048336411271110427836483063457950873824562288934364096546537492367401...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '877830282827664173410176977217...6713514562346659521304714090294'