QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#190455 | #5460. Sum of Numbers | Alfeh | WA | 84ms | 3664kb | C++14 | 1.9kb | 2023-09-28 21:47:03 | 2023-09-28 21:47:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
//const int sz = 1e3 + 3, mod = 998244353;
string sum(string a, string b) {
string ans = "";
int n = a.size();
int m = b.size();
int cary = 0;
int i = n - 1;
int j = m - 1;
while(i >= 0 || j >= 0 || cary) {
if(i >= 0) {
cary += (a[i] - '0');
i--;
}
if(j >= 0) {
cary += (b[j] - '0');
j--;
}
ans += char('0' + (cary % 10));
cary /= 10;
}
reverse(ans.begin(), ans.end());
//cout << a << " " << b << " " << ans << "\n";
return ans;
}
bool cmp(string a, string b) {
if(a.size() != b.size()) return a.size() < b.size();
return a < b;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;
while(t--) {
int n, k; cin >> n >> k;
string c; cin >> c;
string ans = c;
int limit = 1;
for(int i = 1; i <= k; i++, limit *= 3);
for(int i = 0; i < limit; i++) {
int i1 = i;
std::vector<int> v;
int sum1 = 0;
int tot = 0;
for(int j = 0; j < k; j++) {
int len = - 1 + (i1 % 3);
v.push_back(sum1 + len);
tot += sum1 + len;
sum1 += len;
i1 /= 3;
}
if(tot > n || (n - tot) % (k + 1)) continue;
int prt = (n - tot) / (k + 1);
int lst = prt;
string crt = c.substr(0, prt);
for(int j = 0; j < k; j++) {
crt = sum(crt, c.substr(lst, prt + v[j]));
lst += prt + v[j];
prt += v[j];
}
if(cmp(crt, ans)) ans = crt;
}
cout << ans << "\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3420kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 84ms
memory: 3664kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
649607663999112818695535121091271716883103814111526466712058737770955337281586527310775750362280871235076286553850215074801795398406281732371434065121612271001585604761636132649176910707 98449253467064516975946051370424824777341776688849859608679977471459596394177947451956361145217999464679282143853...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '649607663999112818695535121091...1001585604761636132649176910707'