QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358351#5460. Sum of Numberssleepy_shadowTL 1ms3808kbC++142.0kb2024-03-19 19:21:242024-03-19 19:21:25

Judging History

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

  • [2024-03-19 19:21:25]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3808kb
  • [2024-03-19 19:21:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], b[N], c[N], la, lb, lc, n, k, len;
struct node {
    string str;
    bool operator==(const node &tmp) const {
        return str == tmp.str;
    }
    node operator+(const node &tmp) const {
        la = str.size();
        lb = tmp.str.size();
        lc = max(la, lb);
        for (int i = 1;i <= la; ++i) a[i] = str[la - i] - 48;
        for (int i = 1;i <= lb; ++i) b[i] = tmp.str[lb - i] - 48;
        for (int i = 1;i <= lc + 2; ++i) c[i] = 0;
        for (int i = 1;i <= lc; ++i) {
            if (i > la) a[i] = 0;
            if (i > lb) b[i] = 0;
            c[i] += a[i] + b[i];
            if (c[i] > 9) ++c[i + 1], c[i] -= 10;
        }
        while (c[lc + 1]) {
            ++lc;
            if (c[lc] > 9) ++c[lc + 1], c[lc] -= 10;
        }
        node res;
        res.str.clear();
        for (int i = lc;i > 0; --i) res.str += c[i] + 48;
        return res;
    }
}z, ans, it;
string Min(string a, string b) {
    if (a.size() < b.size()) return a;
    if (a.size() > b.size()) return b;
    if (a < b) return a;
    return b;
}
void dfs(node s, int x, int l, int cnt) {
    if (l < 0 || x > n) return ;
    if (cnt == k) {
        it.str = z.str.substr(x, n - x);
        it = it + s;
        ans.str = Min(ans.str, it.str);
        return ;
    }
    it.str = z.str.substr(x, l - 1);
    dfs (s + it, x + l - 1, l - 1, cnt + 1);
    it.str = z.str.substr(x, l);
    dfs (s + it, x + l, l, cnt + 1);
    it.str = z.str.substr(x, l + 1);
    dfs (s + it, x + l + 1, l + 1, cnt + 1);
    return ;
}
void solve() {
    scanf ("%d%d", &n, &k);
    cin >> z.str;
    len = n / (k + 1);
    ans.str = z.str;
    for (int i = 1;i <= n; ++i)
        if((k + 1) * i + k * (k + 1) / 2 >= n && (k + 1) * i - k * (k + 1) / 2 <= n)
            dfs((node){z.str.substr(0, i)}, i, i, 1);
    cout << ans.str;
    puts("");
    return ;
}
int main() {
    int T;
    scanf ("%d", &T);
    while (T--) solve();
    return 0;
}

详细

Test #1:

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

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255
1330897896655974774035586406544907434842835048336411271110427836483063457950873824562288934364096546537492367401...

result: