QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455009#5460. Sum of NumbersWTR2007WA 0ms3760kbC++202.0kb2024-06-25 17:38:182024-06-25 17:38:18

Judging History

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

  • [2024-06-25 17:38:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3760kb
  • [2024-06-25 17:38:18]
  • 提交

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;
inline void Check(int len) {
    for (int i = 0; i <= n; i++) t[i] = 0;
    for (int i = 1, id = 0; i <= k + 1; i++) {
        Add(id + 1, id + len);
        len += op[i];
    }
    for (int i = 0; i <= n; i++) 
        if (t[i] >= 10) t[i + 1] += t[i] / 10, t[i] %= 10;
    bool flag = 0;
    for (int i = n; 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 <= n; i++) ans[i] = t[i];
}
inline void DFS(int dep, int s) {
    if (dep == k + 1 && (n - s) % (k + 1) == 0) 
        return Check((n - s) / (k + 1)), void();
    if (dep == k + 1) return ;
    for (int i = -1; i <= 1; i++) {
        op[dep] = i;
        DFS(dep + 1, s + i * (k - dep + 1));
    }
}
inline void Solve() {
    n = read(); k = read();
    scanf("%s", s + 1);
    for (int i = 0; i <= n; i++) ans[i] = 9;
    DFS(1, 0);
    bool flag = 0;
    for (int i = n; 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: 3760kb

input:

2
8 1
45455151
2 1
42

output:

9090
8

result:

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