QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#75922#5460. Sum of NumbersXKErrorWA 370ms6224kbC++142.2kb2023-02-06 17:36:402023-02-06 17:36:41

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 17:36:41]
  • 评测
  • 测评结果:WA
  • 用时:370ms
  • 内存:6224kb
  • [2023-02-06 17:36:40]
  • 提交

answer

#include <bits/stdc++.h>

#define maxn 20005
#define base 10000

using namespace std;

int T;
int n, k;
int lim;

char s[maxn * 10];

struct bg {
	int n;
	int a[maxn];

	bg() {
		n = 0;
	}

	void clear() {
		memset(a, 0, sizeof a);
//		for (int i = 1; i <= lim + 10; i++) a[i] = 0;
		n = 0;
	}
// 15155
	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] / base;
			b.a[i] %= base;
		}
		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 += 4) {
		res.a[++res.n] = 0;
		for (int j = min(i + 3, r); j >= i; j--) {
			res.a[res.n] = res.a[res.n] * 10 + s[j] - '0';
		}
	}
//	reverse(res.a + 1, res.a + res.n + 1);
	return res;
}

bool qcp(bg &a, bg &b) {
	if (a.n != b.n) return a.n < b.n;
	for (int i = a.n; i > 0 && i > a.n - 100; i--) if (a.a[i] != b.a[i]) return a.a[i] < b.a[i];
	return 0;
//	if (a.n == b.n && a.a[a.n] < b.a[b.n]) return 1;
}

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 (qcp(ans, a[j])) return;
	if (j == 0) return(void)(ans = min(ans, a[j]));
//	cout<<"#"<<endl;
	for (int x = lim; x > 0 && x > lim - 6; --x) {
		if (n - i - x + 1 > (j - 1) * lim) continue;
		if (i + x - 1 > n) continue;
//		a[j - 1].clear();
		a[j - 1] = a[j] + get(i, i + x - 1);
//		cout<<"Next:"<<x<<endl;
		dfs(i + x, j - 1);
	}
}

int main() {
//	freopen("dt.in", "r", stdin);
//	freopen("dt.out", "w", stdout);
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d%s", &n, &k, s + 1);
		reverse(s + 1, s + n + 1);
//		cout<<"@@@"<<endl;
//		(get(1, 4) + get(5, 8)).deb();
		++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: 100
Accepted
time: 0ms
memory: 4584kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 370ms
memory: 6224kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

286183755516647947970677378799138606867646615958794128735093872774957762935663056503435341452643850760388735990935082251928006517442350857537793072219690979786682717925250679901255
13308978966559747740355864065449074348428350483364112711142783648306345795087382456228893436409654653749236740183946316...

result:

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