QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#75921 | #5460. Sum of Numbers | XKError | WA | 3ms | 4596kb | C++14 | 2.2kb | 2023-02-06 17:31:12 | 2023-02-06 17:31:13 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 20005
#define base 10000
using namespace std;
int T;
int n, k;
int lim;
char s[maxn * 10];
struct bg {
int n;
int a[maxn];
bg() {
n = 0;
}
void clear() {
memset(a, 0, sizeof a);
// for (int i = 1; i <= lim + 10; i++) a[i] = 0;
n = 0;
}
bg operator +(bg b) {
b.n = max(b.n, n) + 1;
for (int i = 1; i <= b.n; i++) {
b.a[i] += a[i];
b.a[i + 1] += b.a[i] / base;
b.a[i] %= base;
}
while (b.n && b.a[b.n] == 0) --b.n;
return b;
}
bool operator <(const bg b) const {
if (n != b.n) return n < b.n;
for (int i = n; i; i--) if (a[i] != b.a[i]) return a[i] < b.a[i];
return 0;
}
void deb() {
for (int i = n; i; i--) printf("%d", a[i]);
puts("");
}
} a[10], ans;
bg get(int l, int r) {
bg res;
res.clear();
for (int i = l; i <= r; i += 4) {
res.a[++res.n] = 0;
for (int j = l; j <= l + 3 && j <= r; j++) {
res.a[res.n] = res.a[res.n] * 10 + s[j] - '0';
}
}
// reverse(res.a + 1, res.a + res.n + 1);
return res;
}
bool qcp(bg &a, bg &b) {
if (a.n != b.n) return a.n < b.n;
for (int i = a.n; i > 0 && i > a.n - 100; i--) if (a.a[i] != b.a[i]) return a.a[i] < b.a[i];
return 0;
// if (a.n == b.n && a.a[a.n] < b.a[b.n]) return 1;
}
void dfs(int i, int j) {
// cout<<i<<" "<<j<<" "<<endl;
// a[j].deb();
if (n - i + 1 > j * lim) return;
if (ans < a[j]) return;
// if (qcp(ans, a[j])) return;
if (j == 0) return(void)(ans = min(ans, a[j]));
// cout<<"#"<<endl;
for (int x = lim; x > 0 && x > lim - 6; --x) {
if (n - i - x + 1 > (j - 1) * lim) continue;
if (i + x - 1 > n) continue;
// a[j - 1].clear();
a[j - 1] = a[j] + get(i, i + x - 1);
// cout<<"Next:"<<x<<endl;
dfs(i + x, j - 1);
}
}
int main() {
// freopen("dt.in", "r", stdin);
// freopen("dt.out", "w", stdout);
scanf("%d", &T);
while (T--) {
scanf("%d%d%s", &n, &k, s + 1);
reverse(s + 1, s + n + 1);
// cout<<"@@@"<<endl;
// (get(1, 4) + get(5, 8)).deb();
++k;
lim = (n + k - 1) / k + 1;
// ans = get(1, 4) + get(5, 8);
// cout<<"@"<<k<<endl;
ans.clear();
ans.n = 1e9;
a[k].clear();
a[k].n = 1;
dfs(1, k);
ans.deb();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 4596kb
input:
2 8 1 45455151 2 1 42
output:
6969 6
result:
wrong answer 1st lines differ - expected: '9696', found: '6969'