QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#801539#8932. BingoInfinite_Loopers#RE 0ms0kbC++201.4kb2024-12-07 01:29:232024-12-07 01:29:24

Judging History

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

  • [2024-12-07 01:29:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-12-07 01:29:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void add(auto &&a, ll x) {
	auto it = end(a);
	while (x) {
		--it;
		x = x + (*it - '0');
		*it = '0' + x%10;
		x /= 10;
	}
}

string solve1(string n, string m) {
	if (n.find(m) != n.npos) return n;
	string res(1, '~');
	for (int i = 0; i < ssize(m)+3; i++) {
		string a = n;
		for (int j = 0; j < i; j++) a.rbegin()[j] = '0';
		for (int j = 0; j < ssize(m); j++) a.rbegin()[i+j] = m.rbegin()[j];
		if (a < n) add(ranges::subrange(begin(a), end(a) - i - ssize(m)), 1);
		if (a < res) res = a;
	}
	string a = n;
	int i = ssize(n) - ssize(m) + 2;
	fill(a.begin() + i, a.end(), '0');
	while (true) {
		a[i] = (a[i] - '0' + 1) % 10 + '0';
		if (a.substr(i - ssize(m) + 1, ssize(m)) == m) {
			if (a < res) res = a;
			break;
		}
		if (a[i] != '0') break;
		i--;
	}
	return res;
}

string solve2(string n, string m) {
	ll lm = stoll(m);
	ll r = 0;
	for (char ch: n) {
		r = (r * 10 + ch - '0') % lm;
	}
	add(n, (lm-r)%lm);
	return n;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	int n_tests;
	cin >> n_tests;
	for (int test = 0; test < n_tests; test++) {
		string n, m;
		cin >> n >> m;
		n.insert(0, string(100, '0'));
		add(n, 1);
		//cerr << solve1(n, m) << " " << solve2(n, m) << "\n";
		string ans = min(solve1(n, m), solve2(n, m));
		ranges::reverse(ans);
		while (ans.back() == '0') ans.pop_back();
		ranges::reverse(ans);
		cout << ans << "\n";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

6
7 3
12 3
9 10
249 51
1369 37
2 1

output:


result: