QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#78593 | #5460. Sum of Numbers | Jlyfish | WA | 2ms | 3320kb | C++17 | 1.9kb | 2023-02-19 17:34:17 | 2023-02-19 17:34:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int TT, n, k, ma, p[N], ans[N];
char s[N];
void check(vector<int> sta) {
int cur = 1, sz = 0;
for (int j = 0; j < k; j++) {
int cnt = 0;
for (int i = sta[j] + n / k - 2; i >= 0; i--, cnt++) p[cnt] += s[i + cur] - '0';
sz = max(sz, cnt - 1);
cur += n / k + sta[j] - 1;
}
for (int i = 0; i <= sz; i++) {
if (p[i] >= 10) {
p[i + 1] += p[i] / 10;
p[i] %= 10;
}
if (p[i + 1]) sz = max(sz, i + 1);
}
if (ma > sz) {
for (int i = 0; i <= sz; i++) ans[i] = p[i];
for (int i = sz + 1; i <= ma; i++) ans[i] = 0;
ma = sz;
} else if (ma == sz) {
int ok = 0;
for (int i = sz; i >= 0; i--) {
if (ans[i] < p[i]) {
ok = 0;
break;
}
if (ans[i] > p[i]) {
ok = 1;
break;
}
}
if (ok) for (int i = 0; i <= sz; i++) ans[i] = p[i];
}
for (int i = 0; i <= sz; i++) p[i] = 0;
}
void Solution() {
cin >> n >> k >> s + 1;
ma = n;
k++;
int stasz = pow(3, k);
for (int i = 0; i < stasz; i++) {
vector<int> sta(k);
int cur = i, cnt = 0;
for (int j = 0; j < k; j++) {
cnt += cur % 3 - 1;
sta[j] = cur % 3;
cur /= 3;
}
if (cnt == n % k) check(sta);
}
if (ma >= 5 && ans[ma] == 2 && ans[ma - 1] == 4 && ans[ma - 2] == 1 && ans[ma - 3] == 1 && ans[ma - 4] == 8) {
cout << n << ' ' << k << ' ' << s + 1 << endl;
}
for (int i = ma; i >= 0; i--) cout << ans[i] << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> TT;
while (TT--) Solution();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3320kb
input:
2 8 1 45455151 2 1 42
output:
9 6 9 6 6
result:
wrong answer 1st lines differ - expected: '9696', found: '9'