QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592503#5460. Sum of NumbersBaiyu0123#WA 333ms3980kbC++201.5kb2024-09-26 23:01:412024-09-26 23:01:41

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 23:01:41]
  • 评测
  • 测评结果:WA
  • 用时:333ms
  • 内存:3980kb
  • [2024-09-26 23:01:41]
  • 提交

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-1);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;
		if (n0*k==n) n0--;
		ans.clear();dfs(1,0);
		output(ans);
	}
}
/*
1
9 3
999109191
*/ 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3860kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 333ms
memory: 3980kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

5753035806942451771248086237047478979336795041797482632815807151581355921008619338246331439232755060431255492648721564260307909512104647511464330247378743916101766914464409957520165576300
5807094147185036461177759185516185057030274643466344568549079027151630791520488967533526635755401280680338914304...

result:

wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '575303580694245177124808623704...6101766914464409957520165576300'