QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75873 | #5460. Sum of Numbers | XKError | WA | 547ms | 30692kb | C++14 | 1.4kb | 2023-02-06 15:26:16 | 2023-02-06 15:26:19 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 200005
using namespace std;
int T;
int n, k;
int lim;
char s[maxn];
struct bg{
int n;
int a[maxn];
void clear() {
for (int i = 1; i <= n; 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] / 10;
b.a[i] %= 10;
}
while (b.n && b.a[b.n] == 0) --b.n;
return b;
}
bool operator <(const bg b) const {
if (n < b.n) return 1;
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++) {
res.a[++res.n] = s[i] - '0';
}
reverse(res.a + 1, res.a + res.n + 1);
return res;
}
void dfs(int i, int j) {
// cout<<i<<" "<<j<<" "<<endl;
// a[j].deb();
if (n - i + 1 > j * lim) return;
if (j == 0) return(void)(ans = max(ans, a[j]));
for (int x = lim; x; --x) {
if (n - i - x + 1 > (j - 1) * lim) return;
if (i + x - 1 > n) break;
a[j - 1] = a[j] + get(i, i + x - 1);
dfs(i + x, j - 1);
}
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d%s", &n, &k, s + 1);
++k;
lim = (n + k - 1) / k;
// ans = get(1, 4) + get(5, 8);
// cout<<"@"<<k<<endl;
ans.clear();
dfs(1, k);
ans.deb();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12912kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 547ms
memory: 30692kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
3643487212740800349472686888551814148464560382557782154258648991735463075773466771863277332588565693103301914818440969321433505767069295563754530614887267182613398545970152359449210708177 4086431472740013568165561337121651483130927146104189568452423621287710757890502531282765813858996314884064292873...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '364348721274080034947268688855...2613398545970152359449210708177'