QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107515#5460. Sum of Numbersycccc319#WA 81ms3728kbC++172.3kb2023-05-21 18:59:202023-05-21 18:59:21

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-21 18:59:21]
  • 评测
  • 测评结果:WA
  • 用时:81ms
  • 内存:3728kb
  • [2023-05-21 18:59:20]
  • 提交

answer

#include <bits/extc++.h>

using namespace std;
vector<int> add(vector<int> &A, vector<int> &B) // C = A + B, A >= 0, B >= 0
{
    if (A.size() < B.size()) return add(B, A);
    vector<int> C;
    int t = 0;
    for (int i = 0; i < A.size(); i ++ )
    {
        t += A[i];
        if (i < B.size()) t += B[i];
        C.push_back(t % 10);
        t /= 10;
    }
    if (t) C.push_back(t);
    return C;
}
vector<int>rt;
vector<int> cmp(const vector<int>& a,const vector<int>& b) {
    if(a.size() != b.size()) {
        if(a.size() > b.size()) return b;
        else return a;
    }
    for(int i = a.size() - 1;i >= 0; --i) {
        if(a[i] != b[i]) {
            if(a[i] > b[i])return b;
            else return a;
        }
    }return a;
}
void pr(vector<int>& A) {
    reverse(A.begin(),A.end());
    for(auto x : A)cout<<x;puts("");
}
int main() {
    int T;cin>>T;
    while(T--) {
        int n, k;
        string s;
        cin >> n >> k >> s;
        const int len = (k + n) / (k + 1);
        vector<int>H{0};
        rt.clear();
        function<void(int,int)>dfs = [&](int idx,int cnt) {
                if(cnt == k) {
                    if(H.end()[-1] >= n)return;
                    else {
                        ///cout<<idx<<"{}\n";
                        H.push_back(n);
                        ///pr(H);
                        vector<vector<int>>A;
                        for(int i = 1;i < H.size();++i) {vector<int>G;
                            for(int j = H[i - 1];j< H[i];++j) {
                                G.push_back(s[j] - 48);
                            }///pr(G);
                            reverse(G.begin(),G.end());
                            A.push_back(G);
                        }
                        for(int i = 1;i < A.size();++i)A[0] = add(A[0],A[i]);
                        if(rt.empty())rt = A[0];
                        else rt = cmp(rt,A[0]);
                        H.pop_back();
                        ///pr(rt);
                    }
                    return;
                }

            H.push_back(idx+len);
            dfs(idx+len,cnt+1);
            H.back()++;
            dfs(idx+len+1,cnt+1);
            ///dfs(idx+len-1,cnt+1);
            H.pop_back();
        };dfs(0,0);
        pr(rt);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3360kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 81ms
memory: 3728kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255
3197438559621892674205829834459049132352203251746927424661710033664146470225183453589103628920851985518980073438...

result:

wrong answer 2nd lines differ - expected: '133089789665597477403558640654...7219813869366061308627573151461', found: '319743855962189267420582983445...9188957837360866684247172399710'