QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138625#5460. Sum of Numbersammardab3an#WA 3ms3776kbC++171.6kb2023-08-12 01:54:132023-08-12 01:55:06

Judging History

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

  • [2023-08-12 01:55:06]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3776kb
  • [2023-08-12 01:54:13]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

string add(string a, string b){
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    string res = "";
    int n = a.length();
    int m = b.length();
    int carry = 0;
    for(int i = 0; i < max(n, m); i++){
        int f = 0, s = 0;
        if(i < n) f = a[i]-'0';
        if(i < m) s = b[i]-'0';
        carry += f + s;
        res += '0'+carry%10;
        carry /= 10;
    }
    if(carry) res += '0'+carry%10;
    reverse(res.begin(), res.end());
    return res;
}

string min(string a, string b){
    if(a.length() < b.length()) return a;
    if(a.length() > b.length()) return b;
    int n = a.length();
    for(int i = 0; i < n; i++){
        if(a[i] < b[i]) return a;
        if(a[i] > b[i]) return b;
    }
    return a;
}

map<int, string> dp[10];

string solve(int i, int n, int k, int rem, string &s){
    string res(n, '9');
    if(rem < 0) return res;
    if(i == n){
        if(rem == 0) return "0";
        return res;
    }
    if(dp[rem].count(i)) return dp[rem][i];
    int toDel = n/k;
    for(int can = toDel-3; can <= toDel+3; can++){
        if(can <= 0) continue;
        if(i+can > n) continue;
        res = min(res, add(solve(i+can, n, k, rem-1, s), s.substr(i, can)));
    }
    return dp[rem][i] = res;
}

int main(){

    int t;
    cin >> t;

    while(t--){


        int n, k;
        cin >> n >> k;

        for(int i = 0; i <= 6; i++) dp[i].clear();

        string s;
        cin >> s;

        cout << solve(0, n, k+1, k+1, s) << "\n";

    }

}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3468kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3776kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255
2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735...

result:

wrong answer 2nd lines differ - expected: '133089789665597477403558640654...7219813869366061308627573151461', found: '286183755510664079479706773787...6909797866802717925250679901255'