QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#541434 | #5460. Sum of Numbers | neonaht | WA | 11ms | 3760kb | C++17 | 1.9kb | 2024-08-31 19:24:10 | 2024-08-31 19:24:11 |
Judging History
answer
#include <bits/stdc++.h>
#define DEBUG 0
#define CASES 1
using namespace std;
const int SZ = 2e5 + 7;
const int MX = 1e9 + 7;
const long long MOD = 1e9 + 7;
const long long MXX = (1LL << 61LL);
string s;
int x, y;
string plusz(string a, string b) {
int as = a.size(), bs = b.size();
if(a.size() < b.size()) {
reverse(a.begin(), a.end());
for(int i=0; i<bs-as; i++) a += '0';
reverse(a.begin(), a.end());
}
else {
reverse(b.begin(), b.end());
for(int i=0; i<as-bs; i++) b += '0';
reverse(b.begin(), b.end());
}
string res = "";
int tod = 0;
for(int i=a.size()-1; i>-1; i--) {
int val = a[i] + b[i] - 2*'0' + tod;
res += char((val%10) + '0');
tod = val/10;
}
if(tod) res += '1';
reverse(res.begin(), res.end());
return res;
}
string smin(string a, string b) {
if(a.size() < b.size() || b == "") return a;
else if(a.size() > b.size() || a == "") return b;
for(int i=0; i<a.size(); i++) {
if(a[i] < b[i]) return a;
else if(a[i] > b[i]) return b;
}
return a;
}
string recur(int p, int l, int r) {
if(l == 0 && r == 0) return "0";
string g = "", v = "", A = "", B = "";
for(int i=p; i>p-x; i--) g += s[i];
reverse(g.begin(), g.end());
v = s[p-x] + g;
if(l > 0) A = plusz(g, recur(p-x, l-1, r));
if(r > 0) B = plusz(v, recur(p-x-1, l, r-1));
return smin(A, B);
}
void process(void) {
int n, k;
cin >> n >> k >> s;
x = n/(k+1), y = n%(k+1);
cout << recur(n-1, k+1-y, y) << '\n';
return ;
}
int main() {
#ifndef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
cin.tie(nullptr)->ios::sync_with_stdio(false);
int t(1);
if(CASES) cin >> t;
while(t--) process();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 11ms
memory: 3760kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
56166869813553561441759828456172779572538621756782848227267318253525131157399334175929532675183669333235937353225663135693291828343831837591846336872835859628112882418794418496228622142 268846747384273005169753758641359125882466503632256410237265297283415010131767073759763392276365391094023875224343...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '561668698135535614417598284561...9628112882418794418496228622142'