QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75770 | #5460. Sum of Numbers | chenshi# | TL | 2ms | 3632kb | C++ | 833b | 2023-02-06 10:13:04 | 2023-02-06 10:13:06 |
Judging History
answer
#include<cstdio>
#include<iostream>
using namespace std;
const int o=2e5+10;
int T,n,K,a[9],len,ans[o],v[o];char str[o];
void dfs(int nw,int s){
if(nw==K){
a[K]=n-s;s=0;
for(int i=1;i<=n;++i) v[i]=0;
for(int i=1;i<=K;s+=a[i++]) for(int j=1;j<=a[i];++j) v[a[i]-j+1]+=str[j+s]-48;
for(int i=1;i<n;++i) v[i+1]+=v[i]/10,v[i]%=10;
for(int i=n;i;--i)
if(v[i]>ans[i]) break;
else if(v[i]<ans[i]){
for(int j=1;j<=i;++j) ans[j]=v[j];
break;
}
return;
}
for(int i=max(n-s-(K-nw)*len,1);i<=len&&s+i+K-nw<=n;++i) a[nw]=i,dfs(nw+1,s+i);
}
int main(){
for(scanf("%d",&T);T--;putchar('\n')){
scanf("%d%d%s",&n,&K,str+1);++K;
for(int i=1;i<=n;++i) ans[i]=str[n-i+1]-48;
len=(n+K-1)/K+1;dfs(1,0);
for(int i=n,flg=0;i;--i) if(ans[i]||flg) printf("%d",ans[i]),flg=1;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3632kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Time Limit Exceeded
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...