QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592451 | #5460. Sum of Numbers | Baiyu0123# | TL | 0ms | 3848kb | C++20 | 1.4kb | 2024-09-26 22:37:26 | 2024-09-26 22:37:27 |
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> ans;
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 GGG=0;
void calc() {
vector<int> ret;int mx=0;
for (int i=1;i<=k;i++) {
mx=max(mx,b[i]);
}
ret.resize(mx);
for (int i=1,l=1;i<=k;i++) {
int r=l+b[i]-1;
for (int i=0;r-i>=l;i++) {
ret[i]+=a[r-i];
}
l=r+1;
}
for (int i=0;i<ret.size();i++) {
if (ret[i]>9) {
if (i+1==ret.size()) {
ret.push_back(ret[i]/10);
ret[i]%=10;
break;
} else {
ret[i+1]+=ret[i]/10,ret[i]%=10;
}
}
}
if (ans.empty()||ret<ans) swap(ans,ret);
}
void dfs(int w,int sum) {
if (w==k+1) {
if (sum==n) calc();
return ;
}
for (int i=max(1,n0-2);sum+i<=n&&i<=n0+2;i++) {
b[w]=i;
dfs(w+1,sum+i);
}
}
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;ans.clear();dfs(1,0);
output(ans);
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
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...
output:
5753035806942451771248086237047478979336795041797482632815807151581355921008619338246331439232755060431255492648721564260307909512104647511464330247378743916101766914464409957520165576300 5807094147185036461177759185516185057030274643466344568549079027151630791520488967533526635755401280680338914304...