QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#211460 | #5460. Sum of Numbers | 1722087564 | WA | 0ms | 3840kb | C++14 | 2.1kb | 2023-10-12 16:42:54 | 2023-10-12 16:42:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
int n,T,k;
string str;
vector<int> add(const vector<int> &a, const vector<int> &b) {
vector<int> res;
int t = 0;
for (int i = 0; i < max(a.size(), b.size()); ++i) {
if (i < a.size()) t += a[i];
if (i < b.size()) t += b[i];
res.push_back(t % 10);
t /= 10;
}
while (t) {
res.push_back(t % 10);
t /= 10;
}
while (res.size() > 1 && res.back() == 0) res.pop_back();
return res;
}
vector<int> get(const string &s) {
int len = s.length();
vector<int> res(len);
for (int i = 0; i < len; ++i) {
res[i] = s[len - i - 1] - '0';
}
return res;
}
int com(const vector<int> &a, const vector<int> &b) {
if(a.size()<b.size())
return -1;
else if(a.size()>b.size()) return 1;
else {
for(int i=a.size()-1; i>=0; i--) {
if(a[i]<b[i]) return -1;
else if(a[i]>b[i]) return 1;
}
}
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>T;
while(T--) {
bool flag=true;
cin>>n>>k;
k++;
cin>>str;
vector<int>a=get(str);
vector<int>ans;
for (int ii=0; ii<pow(3,k-1); ii++) {
vector<int> b;
int tmp=ii;
if(n%k==0) {
for(int j=0; j<k; j++) {
if(tmp%3==0) b.push_back(n/k);
else if(tmp%3==1) b.push_back(n/k-1);
else if(tmp%3==2) b.push_back(n/k+1);
tmp/=3;
}
} else {
for(int j=0; j<k; j++) {
if(tmp%3==0) b.push_back((n+k/2-1)/k);
else if(tmp%3==1) b.push_back((n+k/2-1)/k-1);
else if(tmp%3==2) b.push_back((n+k/2-1)/k+1);
tmp/=3;
}
}
int summ=0;
for(auto u:b)
summ+=u;
b.push_back(n-summ);
summ=n;
if(summ!=n) continue;
int pre=0;
vector<int> nowsum;
for(int i=0; i<k; i++) {
string st=str.substr(pre,b[i]);
//cout<<st<<"\n";
vector<int> tmp =get(st);
nowsum=add(nowsum,tmp);
pre+=b[i];
}
if(flag) {
ans=nowsum;
flag=false;
}
if(com(ans,nowsum)==1) {
ans=nowsum;
}
}
for (int i = ans.size() - 1; i >= 0; --i) {
cout << ans[i];
}
cout<<"\n";
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3840kb
input:
2 8 1 45455151 2 1 42
output:
5060 4
result:
wrong answer 1st lines differ - expected: '9696', found: '5060'