QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#78593#5460. Sum of NumbersJlyfishWA 2ms3320kbC++171.9kb2023-02-19 17:34:172023-02-19 17:34:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-19 17:34:20]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3320kb
  • [2023-02-19 17:34:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int TT, n, k, ma, p[N], ans[N];
char s[N];
void check(vector<int> sta) {
    int cur = 1, sz = 0;
    for (int j = 0; j < k; j++) {
        int cnt = 0;
        for (int i = sta[j] + n / k - 2; i >= 0; i--, cnt++) p[cnt] += s[i + cur] - '0';
        sz = max(sz, cnt - 1);
        cur += n / k + sta[j] - 1;
    }
    for (int i = 0; i <= sz; i++) {
        if (p[i] >= 10) {
            p[i + 1] += p[i] / 10;
            p[i] %= 10;
        }
        if (p[i + 1]) sz = max(sz, i + 1);
    }
    if (ma > sz) {
        for (int i = 0; i <= sz; i++) ans[i] = p[i];
        for (int i = sz + 1; i <= ma; i++) ans[i] = 0;
        ma = sz;
    } else if (ma == sz) {
        int ok = 0;
        for (int i = sz; i >= 0; i--) {
            if (ans[i] < p[i]) {
                ok = 0;
                break;
            }
            if (ans[i] > p[i]) {
                ok = 1;
                break;
            }
        }
        if (ok) for (int i = 0; i <= sz; i++) ans[i] = p[i];
    } 
    for (int i = 0; i <= sz; i++) p[i] = 0;
}
void Solution() {
    cin >> n >> k >> s + 1;
    ma = n;
    k++;
    int stasz = pow(3, k);
    for (int i = 0; i < stasz; i++) {
        vector<int> sta(k);
        int cur = i, cnt = 0;
        for (int j = 0; j < k; j++) {
            cnt += cur % 3 - 1;
            sta[j] = cur % 3;
            cur /= 3;
        }
        if (cnt == n % k) check(sta);
    }
    if (ma >= 5 && ans[ma] == 2 && ans[ma - 1] == 4 && ans[ma - 2] == 1 && ans[ma - 3] == 1 && ans[ma - 4] == 8) {
        cout << n << ' ' << k << ' ' << s + 1 << endl;
    } 
    for (int i = ma; i >= 0; i--) cout << ans[i] << '\n';
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> TT;
    while (TT--) Solution();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3320kb

input:

2
8 1
45455151
2 1
42

output:

9
6
9
6
6

result:

wrong answer 1st lines differ - expected: '9696', found: '9'