QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357512 | #5460. Sum of Numbers | sleepy_shadow | WA | 931ms | 5940kb | C++14 | 2.0kb | 2024-03-18 22:09:48 | 2024-03-18 22:09:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], b[N], c[N], la, lb, lc, n, k, len;
struct node {
string str;
bool operator==(const node &tmp) const {
return str == tmp.str;
}
node operator+(const node &tmp) const {
la = str.size();
lb = tmp.str.size();
lc = max(la, lb);
for (int i = 1;i <= la; ++i) a[i] = str[la - i] - 48;
for (int i = 1;i <= lb; ++i) b[i] = tmp.str[lb - i] - 48;
for (int i = 1;i <= lc + 2; ++i) c[i] = 0;
for (int i = 1;i <= lc; ++i) {
if (i > la) c[i] += b[i];
if (i > lb) c[i] += a[i];
c[i] += a[i] + b[i];
if (c[i] > 9) ++c[i + 1], c[i] -= 10;
}
while (c[lc + 1]) {
++lc;
if (c[lc] > 9) ++c[lc + 1], c[lc] -= 10;
}
node res;
res.str.clear();
for (int i = lc;i > 0; --i) res.str += c[i] + 48;
return res;
}
}z, ans, it;
string Min(string a, string b) {
if (a.size() < b.size()) return a;
if (a.size() > b.size()) return b;
if (a < b) return a;
return b;
}
void dfs(node s, int x, int l, int cnt) {
if (l < 0 || x > n) return ;
if (cnt == k) {
it.str = z.str.substr(x, n - x);
it = it + s;
ans.str = Min(ans.str, it.str);
return ;
}
it.str = z.str.substr(x, l - 1);
dfs (s + it, x + l - 1, l - 1, cnt + 1);
it.str = z.str.substr(x, l);
dfs (s + it, x + l, l, cnt + 1);
it.str = z.str.substr(x, l + 1);
dfs (s + it, x + l + 1, l + 1, cnt + 1);
return ;
}
void solve() {
scanf ("%d%d", &n, &k);
cin >> z.str;
len = n / (k + 1);
ans.str = z.str;
for (int i = 1;i <= n; ++i)
if((k + 1) * i + k * (k + 1 >> 1) >= n && (k + 1) * i - k * (k + 1 >> 1) <= n)
dfs((node){z.str.substr(0, i)}, i, i, 1);
cout << ans.str;
puts("");
return ;
}
int main() {
int T;
scanf ("%d", &T);
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 931ms
memory: 5940kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
\x15662100343797225204277502446789828857579568551547592250774864334601311283242073028803767002533508621452754295539859938312340118106030281393997371058824850863372500925692835620882305191728
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '\x1566210034379722520427750244678...3372500925692835620882305191728'