QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667621 | #5460. Sum of Numbers | RPChe_ | WA | 28ms | 15496kb | C++14 | 2.3kb | 2024-10-23 00:54:55 | 2024-10-23 00:54:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k, f[N], d[N];
char s[N];
struct INT {
int a[N], n;
static const int lim = 1, LIM = 10;
void scan(int l, int r) {
n = 0;
int cnt = 0, res = 0, bs = 1;
for (int i = r; i >= l; i--) {
res += (s[i] - '0') * bs;
bs *= 10, cnt++;
if (cnt == 9) {
a[n++] = res;
cnt = 0, res = 0, bs = 1;
}
}
if (res) a[n++] = res;
}
void print() {
if (!n) printf("0");
else {
for (int i = n - 1; i >= 0; i--) printf("%d", a[i]);
}
}
int & operator [] (const int & x) {
return a[x];
}
INT operator + (const INT & b) const {
INT c;
int mx = max(n, b.n), rst = 0;
for (int i = 0; i < mx; i++) {
int A = 0, B = 0;
if (i < n) A = a[i];
if (i < b.n) B = b.a[i];
c[i] = (rst + A + B) % LIM;
rst = (rst + A + B) / LIM;
}
c.n = mx;
if (rst) c[c.n++] = rst;
return c;
}
INT & operator = (const INT & b) {
n = b.n;
for (int i = 0; i < n; i++) {
a[i] = b.a[i];
}
return *this;
}
bool operator < (const INT & b) const {
if (n != b.n) return n < b.n;
for (int i = n - 1; i >= 0; i--) {
if (a[i] != b.a[i]) return a[i] < b.a[i];
}
return 0;
}
} a[7], sm, mn;
void dfs(int dep) {
if (dep > k) {
int tot = 0;
for (int i = 1; i <= k; i++) {
d[i] = d[i - 1] + f[i];
tot += d[i];
}
if (n - tot <= 0 || ((n - tot) % (k + 1))) return;
int l = (n - tot) / (k + 1), nw = 1;
sm.n = 0;
for (int i = 0; i <= k; i++) {
a[i].scan(nw, nw + l + d[i] - 1);
nw += l + d[i];
sm = sm + a[i];
}
mn = min(mn, sm);
return;
}
for (int i = -1; i <= 1; i++) {
f[dep] = i;
dfs(dep + 1);
}
}
int main() {
int T; scanf("%d", &T);
while (T--) {
mn.n = 1919810;
scanf("%d%d%s", &n, &k, s + 1);
dfs(1);
mn.print();
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11568kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 28ms
memory: 15496kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
35803113081937564033872049900 24017128294329237286048634866215037122131106377629539660627487548566268198766325198934843467434406098044352263311745054853320611387044730530966069060565870917947063896488912655721409087470020608160108 420912910889059232044208507918885861597568220704059554849881818529886...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '35803113081937564033872049900'