QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592448 | #5460. Sum of Numbers | Baiyu0123# | WA | 103ms | 3940kb | C++20 | 1.4kb | 2024-09-26 22:36:40 | 2024-09-26 22:36:41 |
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+1;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: 3624kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 103ms
memory: 3940kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
3636733938342862284777290619398546887683961166197063357533275680300947575804595063814840014749117946250672724491502190322946481853515966096183519240978624493356281380857186769171673750050 2242362831813684411794994645919348618874407289487783769626268154373209090046590535431371081837840852271850541562...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '363673393834286228477729061939...3356281380857186769171673750050'