QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455007#5460. Sum of NumbersWTR2007WA 111ms4260kbC++202.0kb2024-06-25 17:37:002024-06-25 17:37:01

Judging History

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

  • [2024-06-25 17:37:01]
  • 评测
  • 测评结果:WA
  • 用时:111ms
  • 内存:4260kb
  • [2024-06-25 17:37:00]
  • 提交

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 + op[i]);
        id += 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: 100
Accepted
time: 0ms
memory: 3744kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 111ms
memory: 4260kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

25349228414355616504355703650453652397786931131337273056188527989067536941165960293275373038511655818488058564977897977346058101997844656655176594052262953235521358807033339576746673932
234320740069166293242197765378410738125349852396203983942538805904719729221581410320335035227413033347126615192468...

result:

wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '253492284143556165043557036504...3235521358807033339576746673932'