QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#592546 | #5460. Sum of Numbers | Baiyu0123# | WA | 98ms | 7928kb | C++20 | 1.6kb | 2024-09-26 23:23:23 | 2024-09-26 23:23:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
int n,k,n0;
int a[maxn],b[maxn];
string s;
vector<int> f[10][100];
bool operator <(const vector<int> &x,const vector<int> &y) {
if (x.size()!=y.size()) return x.size()<y.size();
for (int i=0;i<x.size();i++) {
if (x[i]!=y[i]) return x[i]<y[i];
}
return 0;
}
vector<int> build(int l,int r) {
vector<int> ret;
for (int i=r;i>=l;i--) {
ret.push_back(a[i]);
}
return ret;
}
void output(vector<int> &x) {
for (int i=x.size()-1;i>=0;i--) cout<<x[i];
cout<<"\n";
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T;cin>>T;
while (T--) {
cin>>n>>k;
cin>>s;
k++;
for (int i=1;i<=n;i++) a[i]=s[i-1]-'0';
n0=n/k;
while (n0>=2&&n-n0*k<k*(k-1)/2) n0--;
int m=n-n0*k;
f[0][0].resize(n0);
for (int i=1;i<=k;i++) {
for (int j=0;j<=m;j++) {
for (int p=0;p<=k-1&&p<=j;p++) {
if (i==k&&j!=m) continue;
if (f[i-1][j-p].empty()) continue;
vector<int> wy=f[i-1][j-p];
if (n0+p>wy.size()) wy.resize(n0+p);
for (int q=0,r=i*n0+j;q<n0+p;q++) {
wy[q]+=a[r-q];
}
for (int i=0;i<wy.size();i++) {
if (wy[i]>=10) {
if (i+1<wy.size()) {
wy[i+1]+=wy[i]/10;
wy[i]%=10;
} else {
wy.push_back(wy[i]/10);
wy[i]%=10;
break;
}
}
}
if (f[i][j].empty()||wy<f[i][j]) f[i][j]=wy;
}
}
}
output(f[k][m]);
for (int i=0;i<=k;i++) {
for (int j=0;j<=m;j++) {
f[i][j].clear();
}
}
}
}
/*
1
9 3
999109191
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 98ms
memory: 7928kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
8982894144844721884851867373736997228364759029035719330432666219509341528540535883256703602446306776705540815265222634651881629306083243569485059987231013054055559532991728761868477062042 6033162061432694816962327756126473503075736124852093071582900395617615683907316202581693639627186182411978418530...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '898289414484472188485186737373...4055559532991728761868477062042'