QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#138581#5460. Sum of Numbersammardab3an#WA 16ms3700kbC++171.4kb2023-08-11 23:42:212023-08-11 23:42:22

Judging History

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

  • [2023-08-11 23:42:22]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:3700kb
  • [2023-08-11 23:42:21]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long

using namespace std;

const ll N = 1e6 + 10, MM = 1e9 + 7, MAX = 1e18;

void cal(string& a, string& b) {
	int have = 0;
	int i;
	for (i = 0; i < min(a.size(), b.size()); i++) {
		int add = a[i] - '0' + b[i] - '0' + have;
		a[i]= add % 10 + '0';
		if (add > 9)have = 1;
		else have = 0;
	}
	while (i < a.size()) {
		int add = a[i] - '0' + have;
		a[i] = add % 10 + '0';
		if (add > 9)have = 1;
		else have = 0;
		i++;
	}
	while (i < b.size()) {
		int add = b[i] - '0' + have;
		a += add % 10 + '0';
		if (add > 9)have = 1;
		else have = 0;
		i++;
	}
}

int solve() {
	int n, k; cin >> n >> k;
	k++;
	string s; cin >> s;
	int m = n / k;
	vector<ll>v(k, m);
	for (int i = 0; i < n % k; i++) {
		v[k - 1 - i]++;
	}
	string res = "";
	do {
		string sum = "";
		int curidx = n - 1;
		for (int i = 0; i < k; i++) {
			string cur = "";
			int x = v[i];
			while (x--) {
				cur += s[curidx--];
			}
			cal(sum, cur);
		}
		reverse(sum.begin(), sum.end());
		res = max(res, sum);
		reverse(sum.begin(), sum.end());

	} while (next_permutation(v.begin(), v.end()));
	cout << res << '\n';
	return 0;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	cin >> t;
	int i = 1;
	while (t--) {
		//cout << "case " << i << ": ";
		solve();
	}
	return 0;
}
/*
2
8 5
45455151
2 1
42

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3564kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 16ms
memory: 3700kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255
98793531832534086576037108175262905394453460204573162042253574134407696492927081726782739493243026919222739151649...

result:

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