QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#138594 | #5460. Sum of Numbers | ammardab3an# | WA | 16ms | 3528kb | C++17 | 1.5kb | 2023-08-12 00:38:42 | 2023-08-12 00:38:44 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e6 + 10, MM = 1e9 + 7, MAX = 1e18;
void cal(string& a, string& b) {
int have = 0;
int i;
for (i = 0; i < min(a.size(), b.size()); i++) {
int add = a[i] - '0' + b[i] - '0' + have;
a[i]= add % 10 + '0';
if (add > 9)have = 1;
else have = 0;
}
while (i < a.size()) {
int add = a[i] - '0' + have;
a[i] = add % 10 + '0';
if (add > 9)have = 1;
else have = 0;
i++;
}
while (i < b.size()) {
int add = b[i] - '0' + have;
a += add % 10 + '0';
if (add > 9)have = 1;
else have = 0;
i++;
}
if (have)a += '1';
}
void mx(string&a, string&b) {
if (b.size() > a.size())swap(a, b);
else if(b.size()==a.size()){
if (b > a)swap(b, a);
}
}
int solve() {
int n, k; cin >> n >> k;
k++;
string s; cin >> s;
int m = n / k;
vector<ll>v(k, m);
for (int i = 0; i < n % k; i++) {
v[k - 1 - i]++;
}
string res = "";
do {
string sum = "";
int curidx = n - 1;
for (int i = 0; i < k; i++) {
string cur = "";
int x = v[i];
while (x--) {
cur += s[curidx--];
}
cal(sum, cur);
}
reverse(sum.begin(), sum.end());
mx(res, sum);
} while (next_permutation(v.begin(), v.end()));
cout << res << '\n';
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
int i = 1;
while (t--) {
//cout << "case " << i << ": ";
solve();
}
return 0;
}
/*
2
8 5
45455151
2 1
42
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3520kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 16ms
memory: 3528kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
3643487212740800349472686888551814148464560382557782154258648991735463075773466771863277332588565693103301914818440969321433505767069295563754530614887267182613398545970152359449210708177 2649942334464937947227447463303025498371336102030594072667220062367115685025653911100225182500251150989505913132...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '364348721274080034947268688855...2613398545970152359449210708177'