QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#75885#5460. Sum of NumbersXKErrorWA 2ms19528kbC++141.6kb2023-02-06 15:44:442023-02-06 15:44:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-06 15:44:46]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:19528kb
  • [2023-02-06 15:44:44]
  • 提交

answer

#include <bits/stdc++.h>

#define maxn 200005

using namespace std;

int T;
int n, k;
int lim;

char s[maxn];

struct bg{
	int n;
	int a[maxn];
	
	bg() {
		n = 0;
	}
	
	void clear() {
		for (int i = 1; i <= n; i++) a[i] = 0;
		n = 0;
	}
	
	bg operator +(bg b) {
		b.n = max(b.n, n) + 1;
		for (int i = 1; i <= b.n; i++) {
			b.a[i] += a[i];
			b.a[i + 1] += b.a[i] / 10;
			b.a[i] %= 10;
		}
		while (b.n && b.a[b.n] == 0) --b.n;
		return b;
	}
	
	bool operator <(const bg b) const {
		if (n != b.n) return n < b.n;
		for (int i = n; i; i--) if (a[i] != b.a[i]) return a[i] < b.a[i];
		return 0;
	}
	
	void deb() {
		for (int i = n; i; i--) printf("%d", a[i]);
		puts("");
	}
}a[10], ans;

bg get(int l, int r) {
	bg res;
	res.clear();
	for (int i = l; i <= r; i++) {
		res.a[++res.n] = s[i] - '0';
	}
	reverse(res.a + 1, res.a + res.n + 1);
	return res;
}

void dfs(int i, int j) {
//	cout<<i<<" "<<j<<" "<<endl;
//	a[j].deb();
	if (n - i + 1 > j * lim) return; 
	if (ans < a[j]) return;
	if (j == 0) return(void)(ans = min(ans, a[j]));
//	cout<<"#"<<endl;
	for (int x = lim; x > lim - k; --x) {
		if (n - i - x + 1 > (j - 1) * lim) continue;
		if (i + x - 1 > n) continue;
		a[j - 1] = a[j] + get(i, i + x - 1);
//		cout<<"Next:"<<x<<endl;
		dfs(i + x, j - 1);
	}
}

int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d%s", &n, &k, s + 1);
		++k;
		lim = (n + k - 1) / k + 1;
//		ans = get(1, 4) + get(5, 8);
//		cout<<"@"<<k<<endl;
		ans.clear();
		ans.n = 1e9;
		a[k].clear();
		a[k].n = 1;
		dfs(1, k);
		ans.deb();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 19528kb

input:

2
8 1
45455151
2 1
42

output:

49696
696

result:

wrong answer 1st lines differ - expected: '9696', found: '49696'