QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#610994#8932. Bingoucup-team4975WA 1ms3772kbC++232.8kb2024-10-04 18:40:432024-10-04 18:40:43

Judging History

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

  • [2024-10-04 18:40:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3772kb
  • [2024-10-04 18:40:43]
  • 提交

answer

// #define LOCAL
#include <bits/stdc++.h>
#define FINISH cout << "FINISH" << endl;
#define fir first
#define sec second
#define el '\n'
using namespace std;
using PII = pair<int, int>;
using ll = long long;
const int N = 1000010;
void solve()
{
	string s1;
	ll m, res = 0;
	cin >> s1 >> m;
	for (int i = s1.size() - 1; i >= 0; i--) {
		if (s1[i] != '9') {
			// cout << "! " << i << endl;
			s1[i] = char(s1[i] + 1);
			break;
		}
		else if (i != 0) {
			s1[i] = '0';
		}
		else {
			s1[i] = '0';
			s1 = '1' + s1;
		}
	}
	string s2 = to_string(m);
	for (int i = 0; i < s1.size(); i++) {
		res = res * 10 + (s1[i] - '0');
		res = res % m;
	}
	ll ans = m - res;
	// cout << s1 << " " << s2 << " " << ans << endl;
	for (int i = 0; i <= s1.size(); i++) {
		if (i + s2.size() - 1 >= s1.size())
			break;
		int flag = 1;
		for (int j = 0, k = i; j < s2.size(); j++, k++) {
			if (s1[k] != s2[j]) {
				flag = 0;
				break;
			}
		}
		if (flag == 1) {
			cout << s1 << el;
			return;
		}
	}
	// FINISH
	// cout << s2.size() << endl;
	// cout << s1 << " " << s2 << endl;

	for (int i = min(17, (int)s1.size() - 1); i >= (int)s2.size() - 1; i--) {
		// cout << i << endl;
		int st = s1.size() - 1 - i + 1;
		ll sum1 = m, sum3 = m;
		for (int j = i - s2.size(); j >= 0; j--) {
			sum1 = sum1 * 10 + 9;
			sum3 = sum3 * 10 + (s1[s1.size() - 1 - j] - '0');
			/*cout << j << " " << sum1 << " " << sum3 << " " << s1.size() - 1 -
			   j
				 << " " << s1[s1.size() - 1 - j] << endl;*/
		}
		// cout << endl;
		ll sum2 = 0, _10 = 1;
		// cout << int(s1.size() - 1 - i) << " " << int(s1.size() - 1) << endl;
		for (int j = s1.size() - 1 - i; j <= s1.size() - 1; j++) {
			// cout << " ! " << j << endl;
			sum2 = sum2 * 10 + (s1[j] - '0');
			_10 = _10 * 10;
		}
		if (sum2 < sum1) {
			ans = min(ans, sum1 - sum2);
		}
		else
			ans = min(ans, sum2 + _10 - sum1);
		/*cout << i << " " << sum1 << " " << sum2 << " " << sum3 << " " << _10
			 << endl;*/
	}

	s2 = to_string(ans);
	s1 = "0000000000" + s1;
	if (s1.size() < s2.size()) {
		swap(s1, s2);
	}
	// cout << s1 << " " << s2 << endl;
	for (int i = s1.size() - 1, j = s2.size() - 1; i >= 0 && j >= 0; i--, j--) {
		s1[i] = ((s1[i] - '0') + (s2[j] - '0'));

		if (s1[i] >= 10) {
			s1[i] = char(s1[i] - 10 + '0');
			s1[i - 1]++;
		}
		else
			s1[i] = char(s1[i] + '0');
	}
	// cout << s1 << endl;
	int st = 0;
	for (int i = 0; i <= s1.size(); i++) {
		if (s1[i] == '0')
			continue;
		else {
			st = i;
			break;
		}
	}
	// cout << st << endl;
	for (int i = st; i < s1.size(); i++)
		cout << s1[i];
	cout << el;
	// FINISH
	// cout << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3772kb

input:

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

output:

9
13
10
251
1370
4

result:

wrong answer 6th lines differ - expected: '3', found: '4'