QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#765643#5460. Sum of NumbersO_start#WA 148ms12800kbPython31.8kb2024-11-20 14:53:272024-11-20 14:53:28

Judging History

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

  • [2024-11-20 14:53:28]
  • 评测
  • 测评结果:WA
  • 用时:148ms
  • 内存:12800kb
  • [2024-11-20 14:53:27]
  • 提交

answer

import sys
sys.set_int_max_str_digits(0)
t = int(input())
n, k = 0, 0
s = ''

d = 3


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: 10584kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 148ms
memory: 12800kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

347840363645081653382062198733457399609788754140964806229246055713777492069367318122954306211021409988422938476749902078830780710967994490182218459040912803628981326032094734523981175696903
13308978966559747740355864065449074348428350483364112711104278364830634579508738245622889343640965465374923674...

result:

wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '347840363645081653382062198733...8981326032094734523981175696903'