QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#454997#5460. Sum of NumbersWTR2007WA 0ms3724kbC++202.1kb2024-06-25 17:28:072024-06-25 17:28:07

Judging History

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

  • [2024-06-25 17:28:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3724kb
  • [2024-06-25 17:28:07]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define MULT_TEST 1
using namespace std;
typedef long double ldb;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int N = 200050;
char s[N];
int t[N], ans[N], op[10];
inline int read() {
    int w = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        w = (w << 1) + (w << 3) + ch - 48;
        ch = getchar();
    }
    return w * f;
}
inline void Add(int l, int r) {
    int len = r - l + 1;
    for (int i = 0; i <= len; i++) {
        if (r - i >= l) t[i] += s[r - i] - '0';
        t[i + 1] += t[i] / 10;
        t[i] %= 10; 
    }
}
int n, k, h, len;
inline void Check() {
    for (int i = 0; i <= len + 2; i++) t[i] = 0;
    for (int i = 1, id = 0; i <= k + 1; i++) {
        Add(id + 1, id + len + op[i]);
        id += len + op[i];
    }
    for (int i = 0; i <= len + 2; i++) 
        if (t[i] >= 10) t[i + 1] += t[i] / 10, t[i] %= 10;
    bool flag = 0;
    for (int i = len + 2; i >= 0; i--) {
        if (t[i] == ans[i]) continue;
        if (t[i] < ans[i]) flag = 1;
        break;
    }
    if (!flag) return ;
    for (int i = 0; i <= len + 2; i++) ans[i] = t[i];
}
inline void DFS(int dep, int s) {
    if (dep == k + 2 && s == h) return Check(), void();
    if (dep == k + 2) return ;
    for (int i = -2; i <= 2; i++) {
        op[dep] = i;
        DFS(dep + 1, s + i);
    }
}
inline void Solve() {
    n = read(); k = read();
    scanf("%s", s + 1);
    h = n % (k + 1), len = n / (k + 1);
    for (int i = 0; i <= len + 2; i++) ans[i] = 9;
    DFS(1, 0);
    bool flag = 0;
    for (int i = len + 2; i >= 0; i--) {
        if (ans[i] != 0) flag = 1;
        if (flag) printf("%d", ans[i]);
    }
    if (!flag) printf("0");
    puts("");
}
signed main() {
    int _ = 1;
#if MULT_TEST
    _ = read();
#endif 
    while (_--) Solve();
    return 0;
}
/*
2
8 1
45455151
2 1
42
*/

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3724kb

input:

2
8 1
45455151
2 1
42

output:

9696
-4-842

result:

wrong answer 2nd lines differ - expected: '6', found: '-4-842'