QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#454997 | #5460. Sum of Numbers | WTR2007 | WA | 0ms | 3724kb | C++20 | 2.1kb | 2024-06-25 17:28:07 | 2024-06-25 17:28:07 |
Judging History
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'